Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

cwsoft-shortcode module for SilverStripe 3


Go to End


9 Posts   3896 Views

Avatar
cwsoft

Community Member, 57 Posts

30 August 2012 at 8:56am

Edited: 30/08/2012 8:59am

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

Avatar
cwsoft

Community Member, 57 Posts

17 September 2012 at 6:08am

Edited: 17/09/2012 6:09am

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

Avatar
cwsoft

Community Member, 57 Posts

25 March 2013 at 6:24am

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

Avatar
nmshah

Community Member, 21 Posts

14 July 2013 at 7:59am

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

Avatar
cwsoft

Community Member, 57 Posts

14 July 2013 at 8:37am

Edited: 14/07/2013 8:41am

@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

Avatar
nmshah

Community Member, 21 Posts

16 July 2013 at 5:06pm

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.

Avatar
nmshah

Community Member, 21 Posts

17 July 2013 at 3:52am

Edited: 17/07/2013 4:14am

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?

Avatar
cwsoft

Community Member, 57 Posts

17 July 2013 at 4:36am

Edited: 17/07/2013 4:43am

@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.

Go to Top