{"id":481252,"date":"2008-07-18T15:16:34","date_gmt":"2008-07-18T19:16:34","guid":{"rendered":"https:\/\/segue.middlebury.edu\/view\/html\/node\/481252"},"modified":"2008-07-18T15:16:34","modified_gmt":"2008-07-18T19:16:34","slug":"text-templates","status":"publish","type":"page","link":"https:\/\/segueproject.org\/segue-documentation\/segue-v2\/documentation\/extending-segue\/text-templates\/","title":{"rendered":"Text-Templates"},"content":{"rendered":"<h3>About Text-Templates<\/h3>\n<div>\n<p>Text-templates are simple systems for creating dynamic text similar to MediaWiki templates.<br \/>\nAccess to text-templates is done by adding the following markup to text:<br \/>\n&nbsp;&nbsp;&nbsp; <br \/>\n&nbsp;&nbsp;&nbsp; <font face=\"Courier New\">{{template_name}}<\/font><br \/>\n&nbsp;&nbsp;&nbsp; <br \/>\nAdditionally, optional named parameters can also be passed to text-templates:<br \/>\n&nbsp;&nbsp;&nbsp; <br \/>\n&nbsp;&nbsp;&nbsp; <font face=\"Courier New\">{{template_name|paramName=value|param2Name=value2}}<\/font><\/p>\n<p>Text-templates can be useful for inserting predefined scripts or objects into HTML <br \/>\nwithout allowing cross-site scripting attacks. They can also be used to make common<br \/>\nhtml blocks easier to display or change.<\/p>\n<p>For a listing of Text-Templates that come with Segue, see the Features <a href='https:\/\/segue.middlebury.edu\/dataport\/wordpress\/site\/segue\/node\/481328'>page on Text-Templates<\/a>.<\/p>\n<p>Text templates other than those that come with Segue must be installed by the Segue administrator with access to the Segue installation directory. They cannot be installed by end-users.\n<\/p><\/div>\n<h3>Writing Text-Templates<\/h3>\n<div>\n<p><strong>Name:<\/strong><br \/>\nText-template names should be lowercase letters, numbers, and underscore characters.<br \/>\n<strong><br \/>\nLocation:<\/strong><br \/>\nText-templates that you write should go in the following directory.<br \/>\n&nbsp;&nbsp;&nbsp; <font face=\"Courier New\">segue\/text_templates-local\/<\/font><\/p>\n<p><strong>File Name:<\/strong><br \/>\nName you template file with the template name plus &#8216;.class.php&#8217;. For the following examples<br \/>\nwill will use the name &#8216;video&#8217; for the template described. This means the template file<br \/>\nwould be:<br \/>\n&nbsp;&nbsp;&nbsp; <font face=\"Courier New\">segue\/text_templates-local\/video.class.php<\/font><br \/>\n&nbsp;&nbsp;&nbsp; <br \/>\n<strong>Class:<\/strong><br \/>\nText-templates must contain a class that implements the Segue_Wiki_TextTemplate interface<br \/>\nwhich defines two methods: generate($paramList) and getHtmlMatches($text). <br \/>\nIt must be named with its name prepended by &#8216;Segue_TextTemplates_&#8217;. <br \/>\nUsing our video example:<\/p>\n<pre>&lt;?php<br \/><br \/>class Segue_TextTemplates_video<br \/>\timplements Segue_Wiki_TextTemplate <br \/>{<br \/>\t<br \/>\t....<br \/>\t<br \/>\t\/**<br \/>\t * Generate HTML given a set of parameters.<br \/>\t * <br \/>\t * @param array $paramList<br \/>\t * @return string The HTML markup<br \/>\t * @access public<br \/>\t *\/<br \/>\tpublic function generate (array $paramList) {<br \/>\t\t....<br \/>\t}<br \/>\t<br \/>\t\/**<br \/>\t * Answer an array of strings in the HTML that look like this <br \/>\t * template's output and list of parameters that the HTML <br \/>\t * corresponds to. e.g:<br \/>\t *   <br \/>\t * array(<br \/>\t *\t&quot;&lt;img src='http:\/\/www.example.net\/test.jpg' width='350px'\/&gt;&quot; <br \/>\t *\t\t=&gt; array (\t'server'\t=&gt; 'www.example.net',<br \/>\t *\t\t\t\t'file'\t\t=&gt; 'test.jp',<br \/>\t * \t\t\t\t'width'\t\t=&gt; '350px'))<br \/>\t * <br \/>\t * This method may throw an UnimplementedException if this is not<br \/>\t * supported.<br \/>\t *<br \/>\t * @param string $text<br \/>\t * @return array<br \/>\t * @access public<br \/>\t *\/<br \/>\tpublic function getHtmlMatches ($text) {<br \/>\t\t....<br \/>\t}<br \/>\t<br \/>\t....<br \/>}<br \/><br \/>?&gt;<\/pre>\n<p>\n<strong>Configuration:<\/strong><br \/>\nDefault configuration files are to be placed in the main Segue configuration directory<br \/>\nnamed &#8216;text_template-&#8216; followed by their name followed by &#8216;_default.conf.php&#8217;. Custom<br \/>\nconfiguration files are named the same, but followed by &#8216;.conf.php&#8217;.<br \/>\nUsing our video example the default config file is located at:<br \/>\n&nbsp;&nbsp;&nbsp; <font face=\"Courier New\">segue\/config\/text_template-video_default.conf.php<\/font><\/p>\n<p>and a custom config with different settings would live at:<br \/>\n&nbsp;&nbsp;&nbsp; <font face=\"Courier New\">segue\/config\/text_template-video.conf.php<\/font><\/p>\n<p>You can access the instance of you template in the config file using the getTextTemplate()<br \/>\nmethod on the WikiResolver object. e.g.:<\/p>\n<p>&nbsp;&nbsp;&nbsp; <font face=\"Courier New\">$video = WikiResolver::instance()-&gt;getTextTemplate(&#8216;video&#8217;);<\/font>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>About Text-Templates Text-templates are simple systems for creating dynamic text similar to MediaWiki templates. Access to text-templates is done by adding the following markup to text: &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {{template_name}} &nbsp;&nbsp;&nbsp; Additionally, optional named parameters can also be passed to text-templates:&hellip; <a href=\"https:\/\/segueproject.org\/segue-documentation\/segue-v2\/documentation\/extending-segue\/text-templates\/\" class=\"continue-reading\">More &rarr;<\/a><\/p>\n","protected":false},"author":29,"featured_media":0,"parent":481179,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-481252","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/segueproject.org\/segue-documentation\/wp-json\/wp\/v2\/pages\/481252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/segueproject.org\/segue-documentation\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/segueproject.org\/segue-documentation\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/segueproject.org\/segue-documentation\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/segueproject.org\/segue-documentation\/wp-json\/wp\/v2\/comments?post=481252"}],"version-history":[{"count":0,"href":"https:\/\/segueproject.org\/segue-documentation\/wp-json\/wp\/v2\/pages\/481252\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/segueproject.org\/segue-documentation\/wp-json\/wp\/v2\/pages\/481179"}],"wp:attachment":[{"href":"https:\/\/segueproject.org\/segue-documentation\/wp-json\/wp\/v2\/media?parent=481252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}