CMSMS 1.9.3
Hi all,
I'm struggling a bit to create a UDT that gets an article ID. The tag is getting called in the detail template in the news module. I am trying to get the article ID for the current news entry. (looks like "news_id" in the database)
I think I'm close. Any suggestions?
$gCms = cmsms(); //global $gCms;
$smarty =& $gCms->GetSmarty();
$entry = $smarty->get_template_vars('id');
Thanks.
News > Detail Template > Get Article ID via UDT
Re: News > Detail Template > Get Article ID via UDT
There is no smarty variable called 'id' in a News detail template. There is an $entry->id, however.
You don't need the cmsms() and getSmarty() stuff in your UDT.. $smarty is defined.
What are you using the News ID for?
Code: Select all
$entry = $smarty->get_template_vars('entry');
echo($entry->id);
What are you using the News ID for?
Re: News > Detail Template > Get Article ID via UDT
Wishbone, thanks for the help. I knew I was close, just not familiar with accessing the template variables.
I had a prior UDT that pulled the article ID from the "unfriendly" version of the URL, then queried the database for the category and displayed all the other news for the category on the side of the page. So I just needed to retrofit this UDT for use with friendly URLs.
I had a prior UDT that pulled the article ID from the "unfriendly" version of the URL, then queried the database for the category and displayed all the other news for the category on the side of the page. So I just needed to retrofit this UDT for use with friendly URLs.
Re: News > Detail Template > Get Article ID via UDT
You don't have to query the database to get the category name.. It is available in the detail template as $entry->category. To see what else is available, add {$entry|print_r} to your detail template.
Re: News > Detail Template > Get Article ID via UDT
Thanks, wishbone. What I'm actually after is the other news items that are in the same category. So the query is really for getting all the other news items in the same category.
Re: News > Detail Template > Get Article ID via UDT
I still don't think that a UDT to query the database is necessary to get the news in the same category, since you can do {news category=$entry->category} .. Your method might be the easiest way, since you have it working already, but I find that it's best to use the interface provided us (smarty variables) if at all possible, since the database structure can change at any time in the future. The Smarty interface is less likely to change.
I was helping in another thread (http://forum.cmsmadesimple.org/viewtopi ... =8&t=51906) which had a semi-similar issue where the user wanted a gallery related to the news article in the sidebar. The solution used a similar technique.
I was helping in another thread (http://forum.cmsmadesimple.org/viewtopi ... =8&t=51906) which had a semi-similar issue where the user wanted a gallery related to the news article in the sidebar. The solution used a similar technique.
Re: News > Detail Template > Get Article ID via UDT
I think you are absolutely correct. Your method is preferable. I didn't think of doing it this way - partially just unaware. I probably fell back on a database query too quickly out of sheer habit, rather than considering an alternative within the system.
As you can probably tell, I'm still a bit new to working with the smarty variables. But I'm trying to learn more and improve in this area. This UDT and the resulting question to the community is my first step in this direction.
Thanks for taking the time to guide me in the right direction.
As you can probably tell, I'm still a bit new to working with the smarty variables. But I'm trying to learn more and improve in this area. This UDT and the resulting question to the community is my first step in this direction.
Thanks for taking the time to guide me in the right direction.