Page 1 of 1

[SOLVED] Magic query parameter to skip template processing

Posted: Fri Sep 11, 2015 7:24 pm
by spcherub
In the early days of CMSMS there was a query parameter, which if passed to any URL (served by the CMS) would skip the processing of the template and simply return the content of the main {content} tag. Is this still supported in current versions, specifically 1.12 and 2.0? And if so, can someone remind me what this parameter is?

TIA,
Sanjay

Re: Magic query parameter to skip template processing

Posted: Fri Sep 11, 2015 7:28 pm
by spcherub
For context, what I'm trying to do is implement a system where when a query parameter is passed to the page, it controls the way the template is processed. I tried something like this...

Code: Select all

{if $smarty.get.switch != 1}
<__html>
<head>...</head>
...
</__html>
{else}
Show this text
{/if}
But this throws an "unclosed {else} tag" smarty error.

Any suggestions on if/how this can be achieved?

Thanks,
Sanjay

Re: Magic query parameter to skip template processing

Posted: Fri Sep 11, 2015 10:54 pm
by velden

Code: Select all

?showtemplate=false
I've been doing the same before I guess (used: here). Part of the rendered templates including content can be retrieved using ajax requests. But if the same url is used for a normal http get request (e.g. search engine result) it serves a complete html page.

Code: Select all

{title assign='title'}
{process_pagedata}
{$articleOnly=false}
{if $smarty.post.ajaxRequest == 'true'}{$articleOnly=true}{/if}
{$htmltxt='html'}
{$headtxt='head'}
{$bodytxt='body'}
content assign='content'}

{if !$articleOnly}
<!doctype html>
<{$htmltxt}>
  <{$headtxt}>
     {**}
  </{$headtxt}>

  <!--Body-->
  <{$bodytxt}>
  	<div id="pt-main" class="pt-perspective">
{/if}      
{*start of article*}
      <article>
  
      </article>
{*End of article*}
{if !$articleOnly}	  
		</div>
    <!-- jQuery -->
    <__script__ src="{root_url}/static/templates/metrika/js/jquery.js"></__script>
  </{$bodytxt}>
</{$htmltxt}>
{/if}
Not sure if it's the best way to do it but it works. Use at your own discretion. You need to 'trick' smarty to NOT recognize the <__html>, <head> and </__body> sections.

Re: Magic query parameter to skip template processing

Posted: Sat Sep 12, 2015 12:31 am
by spcherub
@veiden: thanks for the sample code. I did figure out that the head tag needed to be included indirectly. I ended up using a GCB.

Re: Magic query parameter to skip template processing

Posted: Sat Sep 12, 2015 4:47 am
by Jeff

Code: Select all

?showtemplate=false
Will return only the {content} block as you requested.

Re: Magic query parameter to skip template processing

Posted: Sat Sep 12, 2015 1:09 pm
by spcherub
@Jeff - thank you so much. That is exactly what I was looking for.

For my future reference, where can I find reference to this in the documentation? I looked before I asked this time, but may not have ben looking in the right places.

Thanks,
Sanjay

Re: [SOLVED] Magic query parameter to skip template processi

Posted: Sat Sep 12, 2015 4:12 pm
by Jeff