Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I am trying to pass a member's firstName and lastName to the title on a member profile page. I am using segment 2 to capture the username. This works well in the for loop in the block:

{% set thePartner = craft.users.username( craft.request.getSegment(2) ) %}
{% for partner in thePartner %}
First Name and Last Name: {{ partner.firstName}} {{ partner.lastName }}
{% endfor %)

Outside the block, where I set the <title>, it doesn't work. Essentially, I would like to set the full name and use it in the title, like:

{% set fullname = partner.firstName ~ ' ' ~ partner.lastName %}

with something like the following in _layout:

<title>{{ fullname }} | {{ siteUrl }} </title>

How can I pass the full name through?

share|improve this question
    
As you probably don't have only profile pages on your site, remember to only render fullname into the <title> of your _layout template if the var is actually set: {{ fullname ? fullname ~ '|' }}! –  carlcs Aug 2 at 17:00

1 Answer 1

up vote 5 down vote accepted

Since you're just expecting one, you should only look for one. Then you don't have to use a for loop. Plus, fullName is already an attribute of user models. So you can do this for the title:

{% set thePartner = craft.users.username( craft.request.getSegment(2) ).first() %}
<title>{{ thePartner.fullName }} | {{ siteUrl }} </title>

If you're still having trouble, it may be with what segments you are pulling from the URL.

share|improve this answer
    
That's the ticket. Thank you. –  Shanan Galligan Aug 2 at 18:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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