Jul
7
SkyBlueCanvas SiteVars Plugin
Filed Under Plugins, SkyBlueCanvas CMS
I have created a new plugin for SkyBlueCanvas that adds the ability to dynamically insert the values of properties of the site and page objects within the content of articles or from within the HTML of the site templates. The name of the new plugin is SiteVars and I think this is one of the coolest features to date.
Updated
The SiteVars plugin is included in the SkyBlueCanvas core code. This article is still a good reference about how to use the plugin but you do not need to download or install any additional code.
The SiteVars plugin adds a lot of flexibility and power to a SkyBlueCanvas site without requiring any knowledge of PHP or HTML. In fact, you do not even need a lot of knowledge about how the insides of SkyBlueCanvas work to use this plugin.
The plugin uses a simple ASCII-based syntax to insert values from properties that you set in the admin control panel. One of the biggest benefits of this approach is that if the values change, you do not need to update references to these values in your template or content.
There are three basic objects or domains that can be referenced by the plugin’s grammar. These are: site, page and page.link. The syntax is very simple and will always be written like this:
[[ object . property ]]
Notice the double square brackets enclosing the variable on the left and right sides. When you create these tokens, omit the spaces shown above.
Site Variables
| Variable | Description |
|---|---|
| site.name | Insert the name of the site as set in Admin – Settings – Default Info |
| site.url | Insert the URL of the site as set in Admin – Settings – Default Info |
| site.map | Dynamically insert a Site Map based on the site’s Page structure as set in Admin – Pages |
| site.contact_name | Insert the name of the default contact as set in Admin – Settings – Default Info |
| site.contact_title | Insert the title of the default contact as set in Admin – Settings – Default Info |
| site.contact_address | Insert the street address of the default contact as set in Admin – Settings – Default Info |
| site.contact_city | Insert the city of the default contact as set in Admin – Settings – Default Info |
| site.contact_state | Insert the state of the default contact as set in Admin – Settings – Default Info |
| site.contact_zip | Insert the postal code of the default contact as set in Admin – Settings – Default Info |
| site.contact_email | Insert the email address of the default contact as set in Admin – Settings – Default Info |
| site.contact_phone | Insert the phone number of the default contact as set in Admin – Settings – Default Info |
| site.contact_fax | Insert the fax number of the default contact as set in Admin – Settings – Default Info |
Example Usage:
Welcome to [[site . name]]
Page Variables
| Variable | Description |
|---|---|
| page.id | The ID of the current page |
| page.title | The Title of the current page |
| page.url | The URL of the current page (automatically uses SEF URLs if enabled for the site) |
| page.modified(date_format) | Insert the Modified date of the current page. The date_format parameter can be any PHP date format string. Example: “F d, Y h:i A” |
| page.parent.id | The ID of the parent page of the current page (if the current page is a sub-page) |
| page.parent.title | The Title of the parent page of the current page (if the current page is a sub-page) |
Example Usage:
Bread Crumbs: <a href="index.php?pid=[[page . parent . id]]">
[[page . parent . title]]</a> / [[page . title ]]
Page Link Variables
The wrap_tag parameter in each variable below can be any HTML element.
| Variable | Description |
|---|---|
| page.link(*, wrap_tag) | Create links for all pages in the site. |
| page.link(1, 2, 3, wrap_tag) | Create links for any list of individual pages referenced by their ID. |
| page.link(parent, wrap_tag) | Create a link to the parent page of the current page. |
| page.link(children, wrap_tag) | Create links to all of the children of the current page. |
| page.link(first, wrap_tag) | Create a link to the first page as determined by the page order set in Admin – Pages. |
| page.link(last, wrap_tag) | Create a link to the last page as determined by the page order set in Admin – Pages. |
| page.link(next, wrap_tag) | Create a link to the next page as determined by the page order set in Admin – Pages. |
| page.link(previous, wrap_tag) | Create a link to the previous page as determined by the page order set in Admin – Pages. |
| page.redirect(url) | Redirects the page to another URL. |
Example Usage:
Pagination: [[page . link(first)]] -
[[page . link(previous)]] -
[[page . link(next)]] -
[[page . link(last)]]
Example Usage 2:
<h2>Related Articles</h2>
<ul>
[[page . link(children, li)]]
</ul>
Example Usage 3:
[[page . redirect(http://www.skybluecanvas.com)]]
Comments
5 Responses to “SkyBlueCanvas SiteVars Plugin”
Leave a Reply
Hi there, sweet little prog. With this sitevars plugin, is it possible to pass the Menu Text Name? I want to do this so I can setup a “page title” section on my pages.
Thanks, Human.
You can get the Page Title but not the menu text. It should be pretty easy to add the menu title, however, since it is a property of the page. Open /skyblue_root/data/plugins/plugin.sitevars.php in a text editor (not word or a rich text editor – preferably something like NotePad) and add this line:
$html = str_replace(’[[page.menutext]]’, $page->name, $html);
to the plgSiteVars function. Just look for the other string replacement directives that are similarly formatted.
Scott
Amazing thanks! I’m really enjoying this app, but I do have a few questions about how to achieve certain results. Is there a place for this? or just ask here?
Thanks. I’m glad you like it. The best place to post questions is on the forum: http://forum.skybluecanvas.com. I am notified of all new posts and try to respond within 48 hours. We also have a growing community that helps out as well.
Cheers,
Scott
[...] SkyBlueCanvas also has some additional hooks via the SiteVars plugin. The full list is beyond the scope of this article, but you can learn more in the blog post about SiteVars. [...]