[solved] How to use contents of a Content Block twice in the one template?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
chrisbt
Dev Team Member
Dev Team Member
Posts: 204
Joined: Sun Sep 05, 2010 6:11 am

[solved] How to use contents of a Content Block twice in the one template?

Post by chrisbt »

I can't work out how to use the contents of a Content Block twice in the one template. I could do with pointing in the right direction. I'm not sure if it is something really obvious or if I need to work out how to use User Defined Tags...

In the Head of the template I have the following editor entered fields to give the name of the folder for the images to be used and then an list of the images to accessed in a specific order. These are declared as javascript global variables.

Code: Select all

	<__script__ type="text/javascript">
		var gallery_images_folder = '{content block="gallery_folder" label="Gallery Folder (no quotes)" oneline="true" }';
		var gallery_images = [{content label="Gallery Photos - file list (quotes and comma separated)"}];
	</__script>
	<__script__ type="text/javascript" src="scripts/kb-slideshow-controls.js"></__script>
I would also like to use gallery_images[0] in the same template in the HTML body as a non-javascript default for the page. The best I have managed so far is to use a another Content Block and get the editor to enter the filename in both the list and again in the Image_0 field.

Any suggestions for a smarter (only small pun intended) solution greatly appreciated.

...also ... is there a neater solution for passing 'Content Block' data to javascript.

Many thanks.

Chris

PS: Forgive the crudity of beginners solutions above, just trying to get a solution anyway I can and learn on the way. :)

PPS: Using version 1.8.2 and love it.
Last edited by chrisbt on Sun Sep 26, 2010 2:31 pm, edited 1 time in total.
NaN

Re: How to use contents of a Content Block twice in the one template?

Post by NaN »

Dude, did you try the assign param ;)

{content assign="foo"}

This will not print out the content but assign it to a variable called "foo".
Now you can use {$foo} as many times as you want.
User avatar
chrisbt
Dev Team Member
Dev Team Member
Posts: 204
Joined: Sun Sep 05, 2010 6:11 am

Re: How to use contents of a Content Block twice in the one template?

Post by chrisbt »

Hi NaN,

Thanks for pointing me in the right direction. I had tried using the assign paramater, but couldn't get it to work for me.

I eventually worked out that to use {$foo} inside both the and tags I needed to position the {content assign="foo"} inside the tag even though it is after the first use of the {$foo} in the head. When I positioned the {content assign="foo"} inside the tag, {$foo} only worked in section not in the .

If I knew a bit more about Smarty I might understand this. For now I am happy just getting it to work.

Many thanks for your help.

Chris
NaN

Re: How to use contents of a Content Block twice in the one template?

Post by NaN »

Maybe this makes any sense for you:

http://forum.cmsmadesimple.org/index.ph ... #msg227128
http://forum.cmsmadesimple.org/index.ph ... #msg224486

So putting the {content assign...} stuff at the very first place (right after the {processpagedata}) should make it accessible in body as well as in head.
User avatar
chrisbt
Dev Team Member
Dev Team Member
Posts: 204
Joined: Sun Sep 05, 2010 6:11 am

Re: How to use contents of a Content Block twice in the one template?

Post by chrisbt »

Thanks for the links and I will move it to just after the {processpagedata}.  :)
Post Reply

Return to “CMSMS Core”