Insert cms code

jeanmarcvieux
21 Posts
jeanmarcvieux posted this 12 October 2020
Ask a Question

Hello,
It's still me :)
I'am trying to insert joomla connexion code but both PHP or html insertion doesn't work; even shortcode

here my code:

    <?php 
$user = JFactory::getUser();
$userToken = JSession::getFormToken();
if ($user->guest) : ?>
<a href="index.php?option=com_users&view=login" >Connexion</a>
<?php else: ?>
<a href="index.php?option=com_users&task=user.logout&<?php echo $userToken; ?>=1" >Déconnexion</a>
<?php endif; ?>

it's working with themler, could you help me ?
Thanks a lot
Jean-Marc

Hello, It's still me :) I'am trying to insert joomla connexion code but both PHP or html insertion doesn't work; even shortcode here my code: <?php $user = JFactory::getUser(); $userToken = JSession::getFormToken(); if ($user->guest) : ?> <a href="index.php?option=com_users&view=login" >Connexion</a> <?php else: ?> <a href="index.php?option=com_users&task=user.logout&<?php echo $userToken; ?>=1" >Déconnexion</a> <?php endif; ?> it's working with themler, could you help me ? Thanks a lot Jean-Marc

Last edited 12 October 2020 by jeanmarcvieux

Vote to pay developers attention to this features or issue.
6 Replies
Order By: Standard | Newest
Support Team
Support Team posted this 13 October 2020

Hi Jean-Marc,

All custom PHP should be inserted in the PHP control only.
Please insert HTML using echo:

<?php 
$user = JFactory::getUser();
$userToken = JSession::getFormToken();
if ($user->guest) : 
echo '<a href="index.php?option=com_users&view=login" >Connexion</a>';
else: 
echo '<a href="index.php?option=com_users&task=user.logout&<?php echo $userToken; ?>=1" >Déconnexion</a>';
endif; ?>

This should work ok.

...................................................
Sincerely,
Olivia
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

Hi Jean-Marc, All custom PHP should be inserted in the PHP control only. Please insert HTML using echo: <?php $user = JFactory::getUser(); $userToken = JSession::getFormToken(); if ($user->guest) : echo '<a href="index.php?option=com_users&view=login" >Connexion</a>'; else: echo '<a href="index.php?option=com_users&task=user.logout&<?php echo $userToken; ?>=1" >Déconnexion</a>'; endif; ?> This should work ok. ................................................... Sincerely, Olivia Nicepage Support Team Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1 Follow us on Facebook: http://facebook.com/nicepageapp
jeanmarcvieux
21 Posts
jeanmarcvieux posted this 13 October 2020

Hello,
I understand better why in the example there is "echo".
I test that

Thanks a lot,
Jean-Marc

Hello, I understand better why in the example there is "echo". I test that Thanks a lot, Jean-Marc
jeanmarcvieux
21 Posts
jeanmarcvieux posted this 13 October 2020

OK,
It works well.

Have a nice day
Jean-Marc

OK, It works well. Have a nice day Jean-Marc
Support Team
Support Team posted this 14 October 2020

Hi Jean-Marc,

Nice to hear that, feel free to contact us on any occasion.

...................................................
Sincerely,
Hella
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

Hi Jean-Marc, Nice to hear that, feel free to contact us on any occasion. ................................................... Sincerely, Hella Nicepage Support Team Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1 Follow us on Facebook: http://facebook.com/nicepageapp
wjt
8 Posts
wjt posted this 15 February 2023

Olivia, (Nicepage Support Team)
I think I'm trying to do the same... but perhaps different. I have a button on the header of the page: new.acapa.org and the button is "SIGN IN". When a user is logged in, I want to change it to "SIGN OUT". I found the line in the file: content.json:
I'm assuming that the PHP code should be added to the "Header" via addition --- What is wrong with my code:
(I'm sure it something wrong with my syntax)
Thank you ,

  Will

<?php $user $usertoken if ($user-?>guest) :
echo '<a href class u-button-style u-custom-font u-heading-font u-btn-1\">SIGN IN</a>';
else:
echo '<a href class u-button-style u-custom-font u-heading-font u-btn-1\">SIGN OUT</a>';
endif; ?>

Olivia, (Nicepage Support Team) I think I'm trying to do the same... but perhaps different. I have a button on the header of the page: new.acapa.org and the button is "SIGN IN". When a user is logged in, I want to change it to "SIGN OUT". I found the line in the file: content.json: I'm assuming that the PHP code should be added to the "Header" via addition --- What is wrong with my code: (I'm sure it something wrong with my syntax) Thank you , Will &lt;?php $user $usertoken if ($user-?&gt;guest) : echo '&lt;a href class u-button-style u-custom-font u-heading-font u-btn-1\&quot;&gt;SIGN IN&lt;/a&gt;'; else: echo '&lt;a href class u-button-style u-custom-font u-heading-font u-btn-1\&quot;&gt;SIGN OUT&lt;/a&gt;'; endif; ?>
jeanmarcvieux
21 Posts
jeanmarcvieux posted this 16 February 2023

Hello,
Are you working on joomla3 or joomla4
I didn't try this on J4

If you are working on J3 you must add before your code just after the PHP quote :
$user = JFactory::getUser();
$userToken = JSession::getFormToken();

You have to define the user class and the session token class.
Hope it help
Jean-Marc

Hello, Are you working on joomla3 or joomla4 I didn't try this on J4 If you are working on J3 you must add before your code just after the PHP quote : $user = JFactory::getUser(); $userToken = JSession::getFormToken(); You have to define the user class and the session token class. Hope it help Jean-Marc
You must log in or register to leave comments