Adding new pstpl template file.

More
5 years 6 months ago - 5 years 6 months ago #70392 by mwilliams
mwilliams created the topic: Adding new pstpl template file.
Hello,

How can I add a new .pstpl template file to a theme? I'll skip the background information, suffice to say it's necessary.

I'm looking to:
1) Create the .pstpl file and place it in the new theme directory (can do that easily).
2) Insert/call the new .pstpl file at a particular line in startpage.pstpl (I'm having difficulty doing this).

Any ideas other than suggesting not doing it? I don't mind core hacks but would obviously prefer other methods if possible.

Thanks,
Mark.
Last Edit: 5 years 6 months ago by mwilliams.

Please Log in to join the conversation.

More
5 years 6 months ago #70410 by Mazi
Mazi replied the topic: Adding new pstpl template file.
There is a function which puts together the different pstpl files of the template. There is also a "templatereplace()" function to replace placeholders within templates.

I do not recommend to hack the core though. You will have problems when updating later on and other templates might get broken.
Better embedd your changes at some of the existing files since it is probably just some HTML?!?

Maybe you can outline in more detail why you want to do these changes?


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 6 months ago #70428 by mwilliams
mwilliams replied the topic: Adding new pstpl template file.
So the line to call the new .pstpl file in an existing file is "templatereplace({newfile.pstpl})"? I'm guessing that's wrong.

I'm essentially looking for an equivalent to <?php include("newfile.php"); ?> for example.

In brief terms, Limesurvey is running in a custom theme with a particular menu. To keep the menus in sync with other areas of the site after updates, I've written a Bash shell script which screenscrapes the default menu and replaces specified menu files. I'd like to create menu.pstpl which can be automatically replaced by that script when required.

Please Log in to join the conversation.

More
5 years 6 months ago #70429 by Mazi
Mazi replied the topic: Adding new pstpl template file.

mwilliams wrote: So the line to call the new .pstpl file in an existing file is "templatereplace({newfile.pstpl})"? I'm guessing that's wrong.

You are right ... because I didn't say it this way :-)

Why not editing the startpage.pstpl file instead?

You won't be able to call a PHP script inside the template directly but you could use an Ajax call for that.

Another solution might be to simply embedd Limesurvey in an iframe.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 6 months ago #70430 by mwilliams
mwilliams replied the topic: Adding new pstpl template file.
Yep, that was a complete guess on my part!

Will templatereplace() or another function work in the same way as the PHP example? I know the PHP call won't work but that's the type of thing I'm hoping to do. The menu file contains simple HTML so can be any file format (.pstpl, .htm, .php, etc).

Please Log in to join the conversation.

More
5 years 6 months ago #70434 by tpartner
tpartner replied the topic: Adding new pstpl template file.
I would also recommend using an AJAX call to pull in the remote menu file. This would avoid hacking the core code.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 6 months ago - 5 years 6 months ago #70467 by mwilliams
mwilliams replied the topic: Adding new pstpl template file.
Not sure about the AJAX solution as I'm not familiar with it. I've instead written a solution for sed. It's a kludge and will break if I modify startpage.pstpl above a critical line but it works.

It'd be handy to simply call other template files though. I presumed it would be possible as it's fairly straightforward in other CMS. Do you think it's worthwhile creating a feature request?

Thanks for the help.
Last Edit: 5 years 6 months ago by mwilliams.

Please Log in to join the conversation.

More
5 years 6 months ago #70470 by tpartner
tpartner replied the topic: Adding new pstpl template file.
Here's an example of using AJAX to access the remote file.

Let's say your remote menu file is called menuTest.php and lives in your template folder.

Insert the following script into any element in your .pstpl files (say a <div id="menuWrapper">).

It will pull in the contents of menuTest.php and append them to the inner HTML of the element that contains the script (#menuWrapper in this case).
<script type="text/javascript" charset="utf-8">
 
	// Identify the current script element NOTE: must be before $(document).ready(function()
	var scripts = document.getElementsByTagName('script');
	var thisScript = scripts[scripts.length - 1];
 
 
	$(document).ready(function() {
 
		// Identify the current script's parent element 
		var scriptParent = $(thisScript).parent();
 
		// Pull in the remote file
		$.ajax({
			url: '{TEMPLATEURL}menuTest.php',
			dataType: 'html',
			success: function(results){
				// Load the remote file contents into the script parent element
				$(scriptParent).append(results);
			}
		});
 
	});
 
</script>

If you want to completely overwrite the inner HTML, change this:
$(scriptParent).append(results);

To this:
$(scriptParent).html(results);

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
4 years 2 weeks ago #96924 by joss
joss replied the topic: Adding new pstpl template file.
I'm running 2 surveys and I'd like to have different banners each when entering to the survey.
Therefore I made a banner.php file to include into the startpage.pstl file.

My banner.php is
<a href="my-link" target="_blank" title="my title" id="link-logo">
<?php 
	if ($_GET["sid"]=="28836")
		echo "image for survey 1";
	else if ($_GET["sid"]=="69731") 
		echo "image for survey 2";
	else
		echo "default";
?>
</a>
and I changed my pstl file with your code above.
The problem is that even when I enter the surveys I get the "default" echo.
What is wrong?

Thanks for your support

Please Log in to join the conversation.

More
4 years 2 weeks ago #96925 by joss
joss replied the topic: Adding new pstpl template file.
So, I understand that using Ajax, firstly the php loads into html and secondly it is embedded in the pstl file.

The correct question is: How can I pass the get value of the survey id to the Ajax function that prepares banner.php?

Maybe it's a quick solution but when it comes to javascript I'm a real novice
Thanks

Please Log in to join the conversation.

More
4 years 2 weeks ago - 4 years 2 weeks ago #96934 by tpartner
tpartner replied the topic: Adding new pstpl template file.
I don't think you need to go to those lengths to have survey-specific banners.

Place the two banner graphics in your template directory and name them something like banner-28836.png and banner-69731.png.

Then you should be able to use something like this in startpage.pstpl:
<img class="banner" src="{TEMPLATEURL}banner-{SID}.png" />

If you need a default banner, you can use jQuery to modify the src attribute of the image tag.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 4 years 2 weeks ago by tpartner.

Please Log in to join the conversation.

More
4 years 2 weeks ago #96936 by joss
joss replied the topic: Adding new pstpl template file.
Thanks! It was super easy!
The default banner in the example is banner-.png which is again working.

Please Log in to join the conversation.

More
4 years 2 weeks ago #96938 by tpartner
tpartner replied the topic: Adding new pstpl template file.

The default banner in the example is banner-.png which is again working.

Even easier than JavaScript :cheer:

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now