php question: do not display if parameter is empty

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
pieter-jan
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Wed Mar 09, 2016 12:00 pm

php question: do not display if parameter is empty

Post by pieter-jan » Thu Mar 24, 2016 12:55 pm

In a small module i use the following to display a link based on a parameter:

<a href="<?php echo $params->get('block_' . $i . '_urlsite'); ?>" class="sitelink">Website</a>

If the field is left empty, it of course still shows the link (making it href="/")

How can i make it so that if the corresponding field in the backend is left empty, the link as a whole is not shown?
Last edited by toivo on Thu Mar 24, 2016 1:56 pm, edited 1 time in total.
Reason: mod note: moved to 2.5 Coding

User avatar
JTema
Joomla! Guru
Joomla! Guru
Posts: 573
Joined: Sun Apr 13, 2008 8:10 pm

Re: php question: do not display if parameter is empty

Post by JTema » Thu Mar 24, 2016 2:21 pm

try this way

Code: Select all

<?php 
$yourparamater=$params->get('yourparamater')
if($yourparamater!= null){?>
			<a href="<?php echo $params->get('block_' . $i . '_urlsite'); ?>" class="sitelink">Website</a> 
			<?php }else{?>
Leave here blank
<?php }?>
http://www.joomlatema.net - Joomla Extensions and Templates
http://wtnews.joomlatema.net/ - WT News Responsive Joomla News And Magazine Template

pieter-jan
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Wed Mar 09, 2016 12:00 pm

Re: php question: do not display if parameter is empty

Post by pieter-jan » Thu Mar 24, 2016 2:25 pm

Parse error: syntax error, unexpected T_IF in /home/hofrenesse/domains/hofvanrenesse.nl/public_html/modules/mod_hvr_stands/tmpl/default.php on line 110

pieter-jan
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Wed Mar 09, 2016 12:00 pm

Re: php question: do not display if parameter is empty

Post by pieter-jan » Thu Mar 24, 2016 2:58 pm

i realize that the php version would help: 5.3.29

User avatar
zomtec
Joomla! Intern
Joomla! Intern
Posts: 78
Joined: Tue Jan 13, 2015 12:49 pm

Re: php question: do not display if parameter is empty

Post by zomtec » Thu Mar 24, 2016 3:01 pm

missing ; at the end of your line 109

pieter-jan
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Wed Mar 09, 2016 12:00 pm

Re: php question: do not display if parameter is empty

Post by pieter-jan » Thu Mar 24, 2016 3:04 pm

Thats it, you guys are livesavers. thnx!!!

User avatar
JTema
Joomla! Guru
Joomla! Guru
Posts: 573
Joined: Sun Apr 13, 2008 8:10 pm

Re: php question: do not display if parameter is empty

Post by JTema » Thu Mar 24, 2016 3:09 pm

Yees zomtec is right ; should be at the end of that line

Code: Select all

$yourparamater=$params->get('yourparamater') ;
http://www.joomlatema.net - Joomla Extensions and Templates
http://wtnews.joomlatema.net/ - WT News Responsive Joomla News And Magazine Template


Locked

Return to “Joomla! 2.5 Coding”