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

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
Praktikant
New Member
New Member
Posts: 2
Joined: Mon Nov 10, 2014 8:26 am

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

Post 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]
}

psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

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

Post 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.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1974
Joined: Mon Jan 29, 2007 4:47 pm

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

Post 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.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Praktikant
New Member
New Member
Posts: 2
Joined: Mon Nov 10, 2014 8:26 am

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

Post by Praktikant »

Thanks I'll try that and test what works best.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

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

Post 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
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Post Reply

Return to “The Lounge”