Page 1 of 1

How can I call the News-Tag from User defined Tag

Posted: Mon Nov 10, 2014 8:54 am
by Praktikant
I am trying to create a tamplate to distinguish between a mobile and a desktop user. For the mobile version I don't want to show the News, so I made a user defined tag to check on mobiles but from the tag I can't echo the {news} tag. It will only show the tag as text.

How can I use the {news} tag from another tag?
My version of CMSMS is 1.11.4 (Fernandia)

Thanks in advance

Code: Select all

$isMobile = (bool)preg_match('#\b(ip(hone|od)|android\b.+\bmobile|opera m(ob|in)i|windows (phone|ce)|blackberry'.
                    '|s(ymbian|eries60|amsung)|p(alm|rofile/midp|laystation portable)|nokia|fennec|htc[\-_]'.
                    '|up\.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\b#i',         $_SERVER['HTTP_USER_AGENT'] );

if($isMobile==false)
{
  echo"<div id='right'></div>";

  echo"<div id='right_2'></div> ";


 echo"<h2 style='text-align: left; text-indent: 8px;'><a href = 'http://Mywebsite/index.php?page=news'> News</a></h2>";


  echo"<p>&nbsp;</p>";

  [color=#FF8000]echo"<div id='news'></div>{news number='4'}";[/color]
}


Re: How can I call the News-Tag from User defined Tag

Posted: Mon Nov 10, 2014 10:07 am
by psy
Easiest way is to use the CGExtensions smarty tag in your template.

At the top of your page:

Code: Select all

{cge_is_smartphone assign=smartphone}
then in your template:

Code: Select all

{if empty($smartphone)}
.... code here for desktop etc ...
{else}
... code here for iPhone, iPad, Android etc
{/if}
Another way, although nowhere near as efficient, is to use media queries in your CSS to hide the news div when displayed on smaller screen sizes.

Re: How can I call the News-Tag from User defined Tag

Posted: Mon Nov 10, 2014 10:16 am
by Jo Morg
Either way, you can still use your UDT. However you should not mix logic with presentation, so:

Code: Select all

$isMobile = (bool)preg_match('#\b(ip(hone|od)|android\b.+\bmobile|opera m(ob|in)i|windows (phone|ce)|blackberry' .
  '|s(ymbian|eries60|amsung)|p(alm|rofile/midp|laystation portable)|nokia|fennec|htc[\-_]'.
   '|up\.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\b#i',         $_SERVER['HTTP_USER_AGENT'] );
$smarty->assign('isMobile', $isMobile)
And then on the template something similar to what psy proposed:

Code: Select all

{if !$isMobile}
.... code here for desktop etc ...
{else}
... code here for iPhone, iPad, Android etc
{/if}
Just use the alternative that best fits your needs.

Re: How can I call the News-Tag from User defined Tag

Posted: Mon Nov 10, 2014 10:25 am
by Praktikant
Thanks I'll try that and test what works best.

Re: How can I call the News-Tag from User defined Tag

Posted: Mon Nov 10, 2014 12:00 pm
by Rolf
I would go for the solution Psy posted.
But here some related posts at my blog in case you want to do it another way:
https://www.cmscanbesimple.org/blog/sma ... ll-me-link
https://www.cmscanbesimple.org/blog/cal ... from-a-udt

Grtz. Rolf