2

Here's an example:

{% set title = entry.artistFirstName | capitalize ~ ' ' ~ entry.title | capitalize %}

It outputs Firstname title instead of Firstname Title whereas filters are applied on the two concatenated elements. Why and how to add this filter on each of these elements?

  • Does it work as expected if you just use plain text?: {% set title = 'lowercase this' | capitalize ~ ' ' ~ 'lowercase that' | capitalize %} – Ben Parizek Sep 17 '14 at 1:44
  • No: 'Lowercase this lowercase that'. – Romain Poirier Sep 17 '14 at 20:14
3

I've tested these three methods (the first one from AbbeyDesign's answer,) and they seem to work fine with variables, I can't see any obvious reason why they wouldn't:

{% set entry = { artistFirstName: 'hello', title: 'world' } %}

{% set title = (entry.artistFirstName|capitalize) ~ ' ' ~ (entry.title|capitalize) %}
{% set title = "#{entry.artistFirstName|capitalize} #{entry.title|capitalize}" %}
{% set title = [entry.artistFirstName|capitalize, entry.title|capitalize]|join(' ') %}

Results in "Hello World" in each case.

  • That's really strange, I tried each of your methods but each always results 'Hello world'. Note that I use this to set the <title> attribute, at the top of my _entry.html. I'm not trying to add this inside a {% block content %}. Perhaps that's why it's not working in my case? – Romain Poirier Sep 17 '14 at 20:12
  • If you're not sure about whether the block is an issue or not, it may be worth testing these on a page that isn't using extends/block/set or whatever. Give them a shot on a basic page and try to complicate things afterwards. In my tests, the syntax for these is working just fine as well so it's likely a larger context issue. – Ben Parizek Sep 18 '14 at 0:00
0
{% set title = (entry.artistFirstName|capitalize) ~ ' ' ~ (entry.title|capitalize) %}
  • Sorry, this doesn't work for me. – Romain Poirier Sep 16 '14 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.