Some General Principles
Posted: Fri Sep 07, 2007 3:01 am
Okay, some of these topics have been touched upon in past posts, but nothing definative has been written, so
I thought I'd write a few notes about CMS made simple, how it's made, and the underlying reliance on smarty.
I intend here to make this topic sticky, and it should be one of the first things you read when you're asking 'How Do I....'. Most of the time, the information you need is at hand, all you need is the knowledge in how to extract it.
I intend to treat this thread as a work in progress, and will periodically update the top post, in the intents that this will someday work its way into the official CMS documentation, so stay posted people.
1) CMS Made Simple is largely built around smarty (smarty.php.net).
This is the power and the beauty behind CMS made simple. It allows for infinite expandability and customization
without modifying any php files (most of the time).
Therefore, whenever you see a template (page template or module template) smarty is being used, and
you can probably use all of the smarty capabilities inside of them.
The {content}, {news}, {menu}, {stylesheet} and other tags are just smarty plugins that have been written
by Ted, and others, to enable reading data from the database and providing that data to smarty in one way
or another.
Anything with {$xxxxxx} is a smarty variable that can be tested, converted, adjusted, and displayed from
within your templates.
Similarly {cms_module} is yet another smarty plugin that interacts with the database, and with the module
code itself to pull out html code. Most of the modules provide templates that allow you to adjust the output.
All users of CMS made simple need to read the documentation at smarty.php.net/manual to understand alot
of what they can do. If they're still lost, then they should take a look at the News default templates, and the
menumanager default templates, and there you should see that all of the magic in them is just smarty manipulating
the data that was provided by user written php code.
Inside of any CMS page, or module template you can use smarty logic, expressions, modifiers, or other plugins
(including many CMS plugins). The functionality is limitless if you have a bit of an imagination, and the willingness
to learn.
2) When editing page, or module templates, sometimes it isn't obvious what variables are available and how you
can use them.
For this, you need two things:
a) The {get_template_vars} smarty plugin
This smarty plugin is used in debugging and development to list all of the variables that smarty knows about
and their types. When working in any new (to you) template you should use this to see what variables are
available.
The get_template_vars plugin will pollute your output, but that's okay, it's just for debugging and development.
When everything works, you can remove it from the appropriate template. And... if you're really worried about it,
you can put that inside of an HTML comment, and then just look at the output when you do a 'view source'.
i.e.:
b) the "print_r" modifier
building on step a above, sometimes the {get_template_vars} plugin will tell you that something is an 'Object'
or an 'Array'. But it won't tell you what's inside of it. There is a built in smarty capability to use (some) php
functions to expand the contents of these 'hidden' items. One of the functions you can use is print_r
i.e: {$myObjectVariable|print_r}
This will generate a list (recursively) of all of the contents of that variable.
3) Smarty is Reentrant/Recursive (whichever).
(To truly understand recursion, one must first understand recursion)
Anyways, in a nutshell, it means that smarty variables can be declared pretty much anywhere, and be available in
your template. For example, if you had the following code inside of the content of one of your pages:
{assign foo='bar'}
and, your page template was similar to this:
{$content}FOO = {$foo}
You would see the output:
FOO = bar
You may think that that is a trivial piece of information. It isn't. It means that you put calls to one smarty plugin
within the template of another. They can be nested as deep as you need (it's just a matter of memory and time
limits). i.e: This technique is used to allow comments to be used on News articles, or to allow you to embed
smarty code within your News content.... think about it a little.
4) Smarty is linear
That means, that variables and tags that are exported lower in your template my not be necessarily available above.
It also means that you can export information from a lower level template into a higher level template
(as long as the higher level template is called 'after' the lower level one). As well, variable from one module
call can overwrite variables from another.
For example, if you were to use this as a page template:
{get_template_vars}
{menu}
{content}
{get_tempalte_vars}
You could, and probably would see different variables available at each step.
[Added: April 16, 2008]
5) Website developers and designers should not be using wysiwygs, at all... period. They're for content editors, and content editors only.
- If website developers and designers can't make a website without using a wysiwyg, they should probably go back to school. If they can't go back to school, then learn to use GOOGLE.
- I recommend separate login accounts for content editors and designers/developers... and only the content editors should use wysiwygs (because they're expected to know how to write in whatever spoken/written language your content is to be displayed in, not how to code HTML).
- Website designers/developers may not have the best grasp on the punctuation and grammar of the destination language, but should know HTML and CSS without having to use a wysiwyg.
6) Don't mix page logic, or module tags in pages that customers will be editing. This allows the website designer and developer to turn off the wysiwyg.
- Users will screw something up if there is the slightest possibility, so don't give it to them. If your customer will be editing a page that has smarty tags in them, move the smarty tags into the page template.
7) Wysiwyg editors should be trimmed down to such a point that the end user will have a tough time messing up the appearance of your page
- This means removing buttons, limiting styles, and tags that are available to your user to such a point that it's reasonably hard for them to mess up the look and feel of the page.
I thought I'd write a few notes about CMS made simple, how it's made, and the underlying reliance on smarty.
I intend here to make this topic sticky, and it should be one of the first things you read when you're asking 'How Do I....'. Most of the time, the information you need is at hand, all you need is the knowledge in how to extract it.
I intend to treat this thread as a work in progress, and will periodically update the top post, in the intents that this will someday work its way into the official CMS documentation, so stay posted people.
1) CMS Made Simple is largely built around smarty (smarty.php.net).
This is the power and the beauty behind CMS made simple. It allows for infinite expandability and customization
without modifying any php files (most of the time).
Therefore, whenever you see a template (page template or module template) smarty is being used, and
you can probably use all of the smarty capabilities inside of them.
The {content}, {news}, {menu}, {stylesheet} and other tags are just smarty plugins that have been written
by Ted, and others, to enable reading data from the database and providing that data to smarty in one way
or another.
Anything with {$xxxxxx} is a smarty variable that can be tested, converted, adjusted, and displayed from
within your templates.
Similarly {cms_module} is yet another smarty plugin that interacts with the database, and with the module
code itself to pull out html code. Most of the modules provide templates that allow you to adjust the output.
All users of CMS made simple need to read the documentation at smarty.php.net/manual to understand alot
of what they can do. If they're still lost, then they should take a look at the News default templates, and the
menumanager default templates, and there you should see that all of the magic in them is just smarty manipulating
the data that was provided by user written php code.
Inside of any CMS page, or module template you can use smarty logic, expressions, modifiers, or other plugins
(including many CMS plugins). The functionality is limitless if you have a bit of an imagination, and the willingness
to learn.
2) When editing page, or module templates, sometimes it isn't obvious what variables are available and how you
can use them.
For this, you need two things:
a) The {get_template_vars} smarty plugin
This smarty plugin is used in debugging and development to list all of the variables that smarty knows about
and their types. When working in any new (to you) template you should use this to see what variables are
available.
The get_template_vars plugin will pollute your output, but that's okay, it's just for debugging and development.
When everything works, you can remove it from the appropriate template. And... if you're really worried about it,
you can put that inside of an HTML comment, and then just look at the output when you do a 'view source'.
i.e.:
b) the "print_r" modifier
building on step a above, sometimes the {get_template_vars} plugin will tell you that something is an 'Object'
or an 'Array'. But it won't tell you what's inside of it. There is a built in smarty capability to use (some) php
functions to expand the contents of these 'hidden' items. One of the functions you can use is print_r
i.e: {$myObjectVariable|print_r}
This will generate a list (recursively) of all of the contents of that variable.
3) Smarty is Reentrant/Recursive (whichever).
(To truly understand recursion, one must first understand recursion)
Anyways, in a nutshell, it means that smarty variables can be declared pretty much anywhere, and be available in
your template. For example, if you had the following code inside of the content of one of your pages:
{assign foo='bar'}
and, your page template was similar to this:
{$content}FOO = {$foo}
You would see the output:
FOO = bar
You may think that that is a trivial piece of information. It isn't. It means that you put calls to one smarty plugin
within the template of another. They can be nested as deep as you need (it's just a matter of memory and time
limits). i.e: This technique is used to allow comments to be used on News articles, or to allow you to embed
smarty code within your News content.... think about it a little.
4) Smarty is linear
That means, that variables and tags that are exported lower in your template my not be necessarily available above.
It also means that you can export information from a lower level template into a higher level template
(as long as the higher level template is called 'after' the lower level one). As well, variable from one module
call can overwrite variables from another.
For example, if you were to use this as a page template:
{get_template_vars}
{menu}
{content}
{get_tempalte_vars}
You could, and probably would see different variables available at each step.
[Added: April 16, 2008]
5) Website developers and designers should not be using wysiwygs, at all... period. They're for content editors, and content editors only.
- If website developers and designers can't make a website without using a wysiwyg, they should probably go back to school. If they can't go back to school, then learn to use GOOGLE.
- I recommend separate login accounts for content editors and designers/developers... and only the content editors should use wysiwygs (because they're expected to know how to write in whatever spoken/written language your content is to be displayed in, not how to code HTML).
- Website designers/developers may not have the best grasp on the punctuation and grammar of the destination language, but should know HTML and CSS without having to use a wysiwyg.
6) Don't mix page logic, or module tags in pages that customers will be editing. This allows the website designer and developer to turn off the wysiwyg.
- Users will screw something up if there is the slightest possibility, so don't give it to them. If your customer will be editing a page that has smarty tags in them, move the smarty tags into the page template.
7) Wysiwyg editors should be trimmed down to such a point that the end user will have a tough time messing up the appearance of your page
- This means removing buttons, limiting styles, and tags that are available to your user to such a point that it's reasonably hard for them to mess up the look and feel of the page.