[solved]content blocks and printing - Id of the current 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.
Locked
ader

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

Post 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!
Last edited by ader on Tue Mar 04, 2008 5:59 pm, edited 1 time in total.
ader

Re: content blocks and printing

Post 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.
Last edited by ader on Tue Mar 04, 2008 8:53 am, edited 1 time in total.
ader

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

Post 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?
ader

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

Post 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 :)
ader

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

Post 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.
jack4ya
Power Poster
Power Poster
Posts: 294
Joined: Thu Oct 19, 2006 10:07 am

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

Post 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...
Locked

Return to “CMSMS Core”