We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4195
    • 398 Posts
    I created this plugin because of a well-known topic on these forum; the ’limits’ of the default templating methods available.
    There are even some modx specific templating libraries floating around like Chunk TPL but I thought why not use a existing templating engine.
    I think TBS fits more into ModX than Smarty (imho is nice but to bloathed) and it also forces the designer to use valid (x)html markup.

    Name: TinyButStrong Template Engine Plugin (TBS4Modx)
    Version: 1.1.1
    Author: Armand "bS" Pondman ([email protected])
    Updated: June 22, 2006 14:26 CET

    Description:
    Use the TBS templating syntax anywhere in your chunks/templates.

    Usage:
    The variable delimitters are [{variable}] (instead of the default according to TBS manual: [variable])
    Document objects and placeholders are available as [{doc.variable}] and [{ph.variable}].
    See TBS manual for syntax explanation (http://www.tinybutstrong.com/).

    Special Note:
    Because of the way most snippets do there ’templating’ not all is possible in chunks that are renderd in the snippet itself unless the snippet uses the TBS engine in the code.

    Quick Installation and Setup quide:

    1) Download and extract the archive.
    2) Create a directory called "tbs4modx" in your [MODx Directory]/assets/plugins directory
    3) FTP or copy the files into [MODx Directory]/assets/plugins/tbs4modx
    4) a. Create a new plugin in the manager called "TBS4Modx" and copy/paste the contents of tbs4modx.plugin.txt into the code field.
    b. Check the "OnWebPageInit" and "OnWebPagePrerender" event

    (optional: if you have a php5 setup you can replace the include of tbs_class.php with tbs_class_php5.php)

    Update for plugin code 1.1.1:
    /*
     *	Name: TinyButStrong Template Engine Plugin (TBS4Modx)
     *	Version: 1.1.1
     *	Author: Armand "bS" Pondman ([email protected])
     *	Updated: June 22, 2006 14:26 CET
     *
     *  Description:
     *  Use the TBS templating syntax anywhere in your chunks/templates.
     * 
     *  Usage:
     *  The variable delimitters are [{variable}] (instead of the default according to TBS manual: [variable])
     *	Document objects and placeholders are available as [{doc.variable}] and [{ph.variable}].
     *  See TBS manual for syntax explanation (http://www.tinybutstrong.com/).
     *
     */
    
    ## Hide error messages (errors will show up in event log)
    $tbs_hide_errors = true;
    
    ### DO NOT EDIT BEL0W THISE LINE
    include_once $modx->config['base_path'] . "assets/plugins/tbs4modx/tbs_class.php";
    include_once $modx->config['base_path'] . "assets/plugins/tbs4modx/tbs4modx.class.inc.php";
    
    $e = &$modx->Event;
    
    switch($e->name) {
      case 'OnWebPageInit':
      	# create tbs object
    	$modx->tbsTpl = new TBSModx('[{,}]','xxx_');
    	$modx->tbsTpl ->NoErr = $tbs_hide_errors;
    	break;
      case 'OnWebPagePrerender':
    	# take current modx output and use it as a template for tbs
    	$modx->tbsTpl->Source = $modx->documentOutput;
    	# merge added templates with fields/blocks
    	$modx->tbsTpl->MergeAdded();
    	# add document objects
    	$modx->tbsTpl->MergeField('doc','tbsGetDo',true);
    	# add placeholders
    	$modx->tbsTpl->MergeField('ph','tbsGetPh',true);
    	# add POST vars
    	$modx->tbsTpl->MergeField('post',$_POST);
    	# add GET vars
    	# overwrite modx output with tbs handled output
    	$modx->documentOutput = $modx->tbsTpl->Render();
    	break;
      default:
        return;
        break;
    }
    



    Changelog:

    * June 22, 2006 -- version 1.1.1

    - add: toggle debugging for errors in event log

    set $tbs_hide_errors to true or false (default to true)

    TBS templating examples:

    Date markup:
    [{doc.createdon;frm='dd.mm.yyyy hh:nn:ss'}]

    takes created on value and displays it in the defined format

    also see: http://www.tinybutstrong.com/examples.php


    For snippet developers: How to use the TBS templating in your snippet

    First be sure to understand how to use TBS in php without modx (see http://www.tinybutstrong.com/manual.php’ The TBS plugin uses a special wrapper for the TBS class with some extra methods you’ll be using in snippets. More documentation coming up but I tried to make a code example to clear some things up

    $template = $modx->tbsTpl->addTemplate($mysnippet_template);
    $modx->tbsTpl->addField($template,'myvariable',$myvariable);
    $modx->tbsTpl->addBlock($template,'myarray',$myarray); 
    $output = $template;
    


    $modx->tbsTpl->addTemplate( [b]string Template )[/b]
    used for loading your template (string containing html and tbs tags)
    returns a template id/placeholder

    $modx->tbsTpl->addField(string TemplateID, string BaseName, mixed X}
    $modx->tbsTpl->addBlock(string TemplateID, string BaseName, mixed X}

    addField and addBlock are almost identifical to TBS methods MergeField and MergeBlock except they take the template id returned by addTemplate as first argument

    That’s all be sure that your snippet adds the template id (in the example case called $template) to it’s output back to modx

    History:

    * June 19, 2006 -- version 1.1.0

    - added: new release of TBS classes 3.10
    - fix: couple of small ’bugs’
    - code cleanup

    * June 15, 2006 -- version 1.0.2

    - fixed: error when no block or field existed
    - fixed: removed <php in the plugin code

    * June 14, 2006 -- version 1.0

    - added: wrapper class for use in snippets
    - added: POST and GET values
      Armand Pondman
      MODx Coding Team
      :: Jot :: PHx
      • 33337
      • 3,975 Posts
      Sounds cool to me though I have zero experience with coding stuff.

      Thanks for sharing.

      regards,

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 18397
        • 3,250 Posts
        Could you provide an example of something TBS can do that the current MODx parser does not yet support? I have heard many good things about TBS but have never tried it...
          • 1876
          • 835 Posts
          Hi,

          Thank’s to bS

          It enables you to easily display information from your database.
          Modx do that but TBS, with only one file, can more easely "take control" of your data :

          - Grouping sections are displayed every time a column’s value in the record-set changes. You can define header, footer, splitter or parent sections
          - Conditional sections are displayed only if their condition is verified. The condition for display is defined using parameter when
          - The NoData section is a section displayed only if the data source has no records.
          - you can format your data, Date-time, Numeric and Conditional format.

          a great one :
          magnet=tag Indicates an Html zone which must be deleted if the block is merged with no record. (you can unshow a complete block in your template/chunk

          And a lot of another tips.

          I use it to do a listing of client, tools ...
          You SQL and php code can be lighter.

          You have a lot of example on the TBS website with html, php code and the result : http://www.tinybutstrong.com/examples.php

          In 2 or 3 hours you can "take control" of TBS.

          Aour

            • 1876
            • 835 Posts
            hi

            BS, in your example :

            [{doc.createdon;frm='dd.mm.yyyy hh:nn:ss'}]


            you can add locale :

            [{doc.createdon;frm='dd.mm.yyyy hh:nn:ss';locale}]


            it will display 14 Juin 2006 ... time if you have defined before setlocale(LC_TIME,’fr’); at the PHP side.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I add the setlocale(LC_TIME,’fr’); (or whatever I want to pass to the setlocale() function) in the config.inc.php file. Then it’s available for the whole site.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 1876
                • 835 Posts
                Re

                Yes I know, we have a post in the french faq.

                It’s just an example of Tbs functionnality.

                  • 25663 MODX Staff
                  • 12,272 Posts
                  Another incredible one from bS... thanks! laugh
                    Ryan Thrash, MODX Co-Founder
                    Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                    • 4195
                    • 398 Posts
                    *update* I added the POST and GET information to the plugin.
                    new version is 0.991.
                      Armand Pondman
                      MODx Coding Team
                      :: Jot :: PHx
                      • 6726
                      • 7,075 Posts
                      I am not a big fan of templating engine usually, but tbs is a very nice choice and could be a helper for some thing like conditionnals while waiting for the new parser...

                      Thanks a lot for this one bS !
                      I’ll most definitely try it out smiley
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l&#39;outil id