Additional Smarty variables for CMSMS CGBlog

I have released a plugin for CMS Made Simple, for use with with the CGBlog module.

What does this do?

CGBlog (1.3.2 at the time of writing) does not provide a lot of Smarty variables. This plugin provides a quick fix to that problem. It will retrieve information from the summary, detail, or archive view, and assign that information to Smarty variables that you can use anywhere in the page template or the module templates themselves.

How do I use it?

Call this plugin at the very top of your page template using:

{blog_info}

The following Smarty variables will be set if the information is found:

$blog_category_id (for example, 1)
$blog_category_name (for example, Animals)
$blog_archive_year (for example, 2010)
$blog_archive_month (for example, 04)
$blog_archive_month_full (for example, April)

Note: These Smarty variables are not escaped so they can be used for string comparison logic. $blog_category_name may contain special HTML characters, which would cause invalid markup, so be sure to escape it when outputting, for example, {$blog_category_name|cms_escape}.

What about the article name? This is already available in the CGBlog detail template. This also applies to the News module. To place this variable into your page template, add the following code to the top of the CGBlog detail template:

{assign var='blog_article_name' value=$entry->title|cms_escape}

The very first line of your page template should contain:

{process_pagedata}

This assumes $config['process_whole_template'] = false; in config.php (this is the default value in CMSMS 1.7.1).

You can now access $blog_article_name in the <head> section of your page template.

Because of the way CMSMS processes the page template, if you wish to access $blog_article_name in the <body> section of your page template, you will need to do a little extra.

Add this to the first line of your page template:

{content assign='mycontent'}

Then replace your original {content} tag with {$mycontent}.

You should now be able to access $blog_article_name in the <body> section of your page template.

Further reading:
http://calguy1000.com/Blogs/4/60.html
http://forum.cmsmadesimple.org/index.php/topic,30475.45.html

What parameters does it take?

  • (optional) match – String in CSV format, containing other CGBlog modules to check for (case-insensitive). This is useful if you are running multiple instances of the CGBlog module under different names (i.e. you have duplicated/renamed the CGBlog module). If not specified, it will default to ‘CGBlog’. For example: {blog_info match='CGBlog, RGuide, FGuide'}

Download

Download: Blog Info 1.1 (zip, 2.79 kB)
This entry was posted in Web development and tagged , , . Bookmark the permalink.

One Response to Additional Smarty variables for CMSMS CGBlog

  1. Pingback: Tweets that mention Additional Smarty variables for CMSMS CGBlog « Ben's Blog -- Topsy.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>