Jump to:

10993 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » cwsoft-shortcode module for SilverStripe 3

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 1126 Views
  • cwsoft
    Avatar
    Community Member
    57 Posts

    cwsoft-shortcode module for SilverStripe 3 Link to this post

    Hi,

    I updated the "cwsoft-shortcode" module to SilverStripe 3.

    The "cwsoft-shortcode" module builds up on the shortcode function introduced with SilverStripe 2.4. Shortcodes can best be thought of a kind of placeholders entered in the WYSIWYG editor, which gets replaced with PHP output just before beeing displayed on the screen. This allows to add dynamic content to a specific position inside a WYSIWYG page.

    The following shortcodes are implemented:
    - cwsHideMailto: obfuscates the mailto part of mailto links
    - cwsRandomQuote: displays a random quote from a text file
    - cwsRandomImage: displays a random image from your assets folder

    Details, screenshots and download is provided via GitHub:
    https://github.com/cwsoft/silverstripe-cwsoft-shortcode#readme

    Feedback welcome.

    Cheers cwsoft

  • cwsoft
    Avatar
    Community Member
    57 Posts

    Re: cwsoft-shortcode module for SilverStripe 3 Link to this post

    Hi,

    just released cwsoft-shortcode v2.2.0 at GitHub.

    Updates since last version:
    - added TinyMCE Plugin to select available shortcodes via WYSIWYG editor (see screenshot)
    - shortcode skeleton code is taken over to the editor content field (one only needs to update pathes etc.)
    - updated 3rd party packages jQuery and ColorBox to latest versions available

    Details and download via GitHub.
    https://github.com/cwsoft/silverstripe-cwsoft-shortcode#readme

    Feedback welcome.

    Cheers cwsoft

  • cwsoft
    Avatar
    Community Member
    57 Posts

    Re: cwsoft-shortcode module for SilverStripe 3 Link to this post

    Hi,

    just released cwsoft-shortcode v2.2.0 at GitHub.

    Updates since last version:
    - prepared for usage with Composer
    - fixed regressions with deprecated functions of future SS 3.1.0 release

    Details and download via GitHub.
    https://github.com/cwsoft/silverstripe-cwsoft-shortcode#readme

    Feedback welcome.

    Cheers cwsoft

  • nmshah
    Avatar
    Community Member
    21 Posts

    Re: cwsoft-shortcode module for SilverStripe 3 Link to this post

    Can I use this module to create a Shortcode to display latest blogentry based on specific tags on different pages?

  • cwsoft
    Avatar
    Community Member
    57 Posts

    Re: cwsoft-shortcode module for SilverStripe 3 Link to this post

    @nmshah: No and yes.

    No you can't with cwsoft-shortcodes as it is delivered. By default the module ships with three shortcode methods ready to use out of the box.

    But yes, you can code your own shortcode methods and add and manage it via cwsoft-shortcode module.

    Another option may be to use one of the existing Widgets available, like Latest Blogs etc.

    Hope it helps

  • nmshah
    Avatar
    Community Member
    21 Posts

    Re: cwsoft-shortcode module for SilverStripe 3 Link to this post

    Thank you for your response.

    I have searched but have not found the latest blog widget for silverstripe 3.1. Are you aware of one and if yes can you please point me in the right direction.

  • nmshah
    Avatar
    Community Member
    21 Posts

    Re: cwsoft-shortcode module for SilverStripe 3 Link to this post

    I am trying to create a custom shortcode to display latest blogs based on tags by using the existing shortcodes as a point of reference.

    I added a new page cwsShortCodeTagBasedBlog.php under cws-shortcode/code

    <?php

    class cwsShortCodeTagBasedBlog {

       public static function cwsShortCodeTagBasedBlogHandler($arguments, $content = null, $parser = null) {
          // only proceed if tag was defined
          if (! isset($arguments['tag'])) return;
          
          // sanitize user inputs
          $tag = Convert::raw2sql($arguments['tag']);
          
          $holder = BlogHolder::get()->First();
          $TagBasedBlog = ($holder) ? BlogEntry::get("Tags LIKE '%$tag%' ")->sort('Date DESC') : false;

          // exit if user defined folder does not contain any image
          if (! $TagBasedBlog) return;
          
          $data = array(
             'TagBasedBlog' => $TagBasedBlog->First(),
          );
                
          // load template and process data
          $template = new SSViewer('TagBasedBlog');
          return $template->process(new ArrayData($data));
          
       }
    }

    and added the following line to cws-shortcode/_config.php

    ShortcodeParser::get()->register('cwsTagBasedBlog', array('cwsShortCodeTagBasedBlog', 'cwsShortCodeTagBasedBlogHandler'));

    Then I recreated the database and flushed the cache. Now I need to know a couple of things:

    1. I would like to know if the above code is alright or do I need to modify the same?
    2. Inspite of adding the line to _config.php in the tinymce editor on the admin side of pages I still don't see the new shortcode. How do I register this new shortcode?

  • cwsoft
    Avatar
    Community Member
    57 Posts

    Re: cwsoft-shortcode module for SilverStripe 3 Link to this post

    @nmshah: Don't know if your Blog Shortcode is right as i do not have installed a blog module for testing here locally.

    However, to get a shortcode working, the following steps are needed:
    - add your shortcode code to subfolder code and ensure the code is doing what you want
    - register the new shortcode via _config.php (as you have done already)
    - add shortcode skeleton to "plugins/shortcode/dialog.htm" option list so it shows up after click on coffee icon

    After this, your shortcode should be ready for usage from inside a WYSIWY page like: [cwsTagBasedBlog]

    As you have defined a template in your shortcode method via $template = new SSViewer('TagBasedBlog') you also need to add a template file to cwsoft-shortcode/templates/Includes/TagBasedBlog.ss.

    Finally call yourdomain.com/dev/build?flush=all to rebuild the database and to register the new template.

    Cheers

    P.S.: To check if shortcode registration did work, you can temporarily make your shortcode method easier to debug by just adding return "hello world"; as first line inside your custom method cwsShortCodeTagBasedBlogHandler.

    1126 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.