Embedding Templates is simply to Copy the template into the Code Block Editor where in the location of the Editor Cursor. Currently CJT is not adding any Tags to the embedded templates, its simply geta Template copy.

If the embedded Templates is then updated later it doesn’t reflect that update to the Code Block as its already copied. If reflecting update is required Linking Template then would be used instead of embedding.

Template can be embedded to the same Code Block Multiple time, CJT is not confirming that. Its up to Block Author to handle em,bedding Templates unlike Linking Templates is linked to the Block only once and managed by the CJT internal Queue.

When writing Javascript and CSS Templates it would be considered like writing separated .js or .css files, no <script> or <style> or <link> tags should be added in those templates. Those Tags are being added automatically by CJT Templates linker. Adding those tag would break those Templates.

Embedding Template is current will embedded Javascript and CSS templates without any tags appended. Its still a good practice to follow the Above strategy of avoiding adding any Tags as next CJT release would start adding those templates while embedding too.

CJT Template Lookup allows WordPress built-in Scripts and Styles to be linked or embedded to Code Blocks. Its one of the powerful features that CJT Template Lookup is providing for Blocks. Almost there is no Third-Party script is not depending on some famous scripts like jQuery. CJT user don’t have to add those manually or copy their codes into the Code Blocks. They’re all available through Template Lookup.

Its the most useful feature provided by Templates system. Linking Template is to Import Template into one or more Code Block. The method of how the Template would be linked by CJT is based on the Template Type/Language. Each Type is linked differently. We’re going to show how each type would be linked.

HTML & PHP

CJT Template Linker is appending all the Templatee Code that being linked to the Block and then execute them all (including Block code) as PHP code.

Example:

Block

<div id="block-layer">
<span><?php echo 'Hello World'; ?></span>
</div>

Linked HTML Template

<div class="block-footer"></div>

Linked PHP Template

<span><?php echo "Footer Text"; ?></span>

All the above Codes would be aggregated as following and then executed as PHP.

<div id="block-layer">
<span><?php echo 'Hello World'; ?></span>
</div>
<div class="block-footer"></div>
<span><?php echo "Footer Text"; ?></span>

The Final Result would be:

<div id="block-layer">
<span>Hello World</span>
</div>
<div></div>
<span>Footer Text</span>

Javascript and Stylesheets

CJT is linked Javascript and Stylesheet Templates by using <script> and <link> HTML tags respectively.

Linking Template can be used when centralizing a peace of code is required. As Multiple Code Blocks can be linked to the same Template file its force a centralisation as those all code Blocks is being use one Template file.

Updating Centralised Template file is always reflected to the Blocks so there is no need to re-link code Blocks after updating the Template file.

Template Types is to tell CJT what Language specifications (Syntax Highlights, Error Checker, etc…) and also tell Template Linker of how to link this Template. Finally its used by the Template Author for identifying different type of scripts (Javascript, CSS, etc…). Different types would be handled differently while its being linked.

Currently, CJT is support the following Types/Languages for Templates:

  • HTML
  • Javascript
  • CSS
  • PHP

Deleting Template is to remove the Template record from the database and also unlink it from all the Block that being linked this Template. This is it! Embedded Template is getting a copy from the template code and pasting it to code Block and deleting Template has no effect on embedded templates. Only linked Blocks would lose the deleted template, those Blocks should be updated as the dependencies has been changed.

Creating a template is a very easy process that required few fields to be filled.

  • Name: Require template name that would be used when link/embedded templates through Templates Lookup. Please keep the name clean, brief and descrbing the Job of the template. Once the template is created this field cannot be changed.
  • Language: Require template language to be used by identifying the template type and how it would be linked by CJT. Its also set the Editor Syntax Highlight and Error checker based on the selected language. Once the template is created this field cannot be changed.

Currently the following languages are being supported:

  • HTML
  • Javascript
  • CSS
  • PHP
  • Template State: Require template state to identify the Publish state. The following state are being supported.
    • Draft: Won’t be displayed in the Templates Lookup form so it cannot be linked or embedded.
    • Published: Template is published and ready to be used. It will displayed in the Lookup form and can be liked or mbedded.
    • Trash: In order to delete template it must passed to this state first.
  • Code: Require template code that builds up the Template.
  • Description: Optional field to describe Template Job.
  • Keywords: Not being used however author might use it any private uses.
  • Version, Revision State and Revision Note: Template is internally revisioned. By mean that it saves the history of all the changes that has been made to the Template however CJT is currently not exposing Restoring to Revision functionality but it would be in the feature. Every time Template code is changed a revision is internally created for the template. User should specify revisions number for tracing their changes as the next releases would expose this functionality.
  • Template is a peace of reusable code that can be embedded or linked to code Blocks, Global or Metabox Blocks.

    Unlike code Blocks that is just created to do specific function by assigned to specific requests. Templates is to be used by Code Blocks as Code Libraries that might be required to be used by Multiple Code Blocks. It is independent peace of code and not related to anything. It can either embedded or Linked to code Blocks.

    It keeps Blocks code cleaned and organised as it give the chance to separate the Code into Model and Library codes that is represented in CJT as Block and Template.

    Its originally developer for big library files that is not logically related to the Block Model, might be reused by other Blocks and provided by third-party developers. jQuery is an example of using Templates as its not a part of the code Block and also it shouldn’t be in the code Block as its huge file that would prevent you from editing your code in a simple professional way. Also having those huge library files away from code Block is great for performance as those template files is rarely modified.