Page 1 of 1

[solved]content blocks and printing - Id of the current template?

Posted: Mon Mar 03, 2008 4:28 pm
by ader
Hi,
I'm using CMSMS MLE v. 1.2.3 "Black Rock".

Every of my templates includes some {content} and {content block ...} tags. Above each of those tags there are some Global Content Blocks with text. Every template has different content block and global content blocks.

The problem is I don't know how to print this content depending on a template. Is it possible that the print template checks the name of the current template? For example somethin like:

Code: Select all

{title}<br/>{content}

{if template = 'Template A'}
<h1>{global_content name="TempA_Head1"}
{content block="TempA_Cont1"}
...
{/if}

{if template = 'Template B'}
<h1>{global_content name="TempB_Head1"}
{content block="TempB_Cont1"}
{/if}
This method would be perfect if the {content block}'s could be included in Global Content Blocks but I discovered if i put {content block=...} tags inside a {global_content ...} and then put this Global Content Block inside a template no textarea is created when adding/editing content.

I spent a lot of time on it and i'm still without solution. There were some topics on this forum related to mine, but any of them helped me.

Thank you in advance!

Re: content blocks and printing

Posted: Tue Mar 04, 2008 8:24 am
by ader
I wrote a following UDT:

Code: Select all

global $gCms;

$tempop =& $gCms->GetTemplateOperations();
$temp =& $tempop->LoadTemplateByID($tempId);

return $temp->name;
How can I find the Id of the current template, so i could inster it instead of $tempId? There is a function named TemplateId(), which can be found in lib/classes/contenttypes/Content.inc.php in line 204, but I don't know how to use it. I don't know much about PHP.

TemplateId() is defined in class.content.inc.php line 404 and returns $mTemplateId.

Re: [solved]content blocks and printing - Id of the current template

Posted: Tue Mar 04, 2008 5:59 pm
by ader
ok, here is the solution. It's not the best one, but enough for my purpose.


In backend/content/printing/Link template:

Code: Select all

{capture assign=CurrTemp}
{foreach from=$nodelist item=node}{if $node->current==true}{$node->titleattribute}{/if}{/foreach}
{/capture}

{if $CurrTemp=='TemplateA'}
{capture assign='TemplateContent'}
<h1>{global_content name='TemplateA_Header1'}</h1>
{content block='TemplateA_Content1'}

<h1>{global_content name='TemplateA_Header2'}</h1>
{content block='TemplateA_Content2'}

{/capture}
{/if}

{if $CurrTemp=='TemplateB'}
{capture assign='TemplateContent'}

<h1>{global_content name='TemplateB_Header1'}</h1>
{content block='TemplateB_Content1'}

...

{/capture}
{/if}
I don't use WYSIWYG editor for global contents so that's why they are between tags.


In backend/content/printing/Print template add just add {$TemplateContent}.

Prepare your stylesheet and that's it. If someone has a better idea please post it.
It's sad the PDF template can't work in the similar manner. Maybe someone knows how to generate content blocks to pdf?

Re: [solved]content blocks and printing - Id of the current template?

Posted: Thu Mar 06, 2008 8:37 am
by ader
Sorry, fotgot to add it's based not on a ID of the current template but on th Title Attribute

To load the name of the template to the input field of the title attribute add this code to the ValidateData() function placed in line 321 in Content.inc.php

Code: Select all

	if ($this->mTitleAttribute == '')
	{
		global $gCms;
		$templateops =& $gCms->GetTemplateOperations();	
		$currenttemp =& $templateops->LoadTemplateByID($this->mTemplateId);
		$tempname =& $currenttemp->name;
		$this->mTitleAttribute = $tempname;
		$result = true;
	} 
Now it's ready solution and I hope some of you will find it useful :)

Re: [solved]content blocks and printing - Id of the current template?

Posted: Mon Mar 10, 2008 1:11 pm
by ader
hah, it seems i reply to myself ;] I just discovered that mentioned solution doesn't work if only print button is displayed. There must be both PDF and Print. To have both and display only one the quickest method is:

Code: Select all

{print showbutton=false pdf=true text=''}{print showbutton=true script=true popup=true}
Now it's 100% solution :P I just hope someone will find it useful.

The End.

Re: [solved]content blocks and printing - Id of the current template

Posted: Mon Aug 25, 2008 12:52 pm
by jack4ya
ader wrote: ...

Prepare your stylesheet and that's it. If someone has a better idea please post it.
It's sad the PDF template can't work in the similar manner. Maybe someone knows how to generate content blocks to pdf?
I would like to know the same thing...