Documentation:UBC Content Management System/Shortcodes/ubc use template shortcode

From UBC Wiki

Using a template file within the loop or iso shortcode

With the addition of the new plugin which can be found at https://github.com/ubc/ubc-use-template-shortcode you are now able to load a template file which is created from within that plugin. This means that it's now longer possible to have complex markup and logic from within a template file and not have that in the WordPress post editor.

The templates that are available are explicitly in the plugin's templates directory.

In order to use a template you specify a path which is a combination of a department and a template name. i.e. in the initial release of this plugin there are 2 template files. They are in /templates/education/programs.php and /templates/education/thumb-date-excerpt.php

To use these templates you would do the following;

[ubc_template department='education' template='programs']

[ubc_template department='education' template='thumb-date-excerpt']

You will see that you don't append .php to the template argument. This is automatically added for you.

As a full example;

[loop query="posts_per_page=100" pagination="true"]

[ubc_template department='education' template='thumb-date-excerpt']

[/loop]

The template files contain lots of documentation at the top of each one. If you wish to create your own template, make a pull request on github with your template added to an appropriate directory. i.e. if you're creating a template for arts for showing posts in a 'stuff' category with custom fields, you'd create a file such as /templates/arts/stuff-posts-with-extra-things.php

It is imperative that you follow the WordPress coding standards in your template files. On top of that you *must* escape content using WordPress native escaping functions - see the examples as mentioned above and https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data

See Also

Other shortcodes were affected with the 4.2.3 upgrade. Please see the following;