leham789
leham789

Reputation: 117

Cakephp echo username into page title

I am currently learning Cakephp and have made a profile page of which displays the username on it. You can only access this page when logged in so when you are on this page, I wish to display the username of the user in the HTML page title. This is also because your profile page is visible to other users.

At the moment to get the page headers I have used.

<title><?php echo $this->fetch('title'); ?> | Site Name</title>

<? $this->assign('title', 'Profile')?>

And to display the username on the page currently I have:

<?php echo $user['User']['user_name']; ?>

I have attempted to combine these two into something like shown below but clearly that's not working. Any ideas?

<? $this->assign('title', '<?php echo $user['User']['user_name']; ?>')?>

Thanks!

Upvotes: 1

Views: 85

Answers (1)

bikash.bilz
bikash.bilz

Reputation: 821

Mistake in the concatenation, change this in your .ctp

<? $this->assign('title', '<?php echo $user['User']['user_name']; ?>')?>

to this

<? $this->assign('title', $user['User']['user_name'])?>

Later on add this in your layout

<title><?php echo $this->fetch('title'); ?> | Site Name</title>

This will work :)

Upvotes: 1

Related Questions