Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi
  • Page :
  • 1
  • 2

SUJET : Adding new pstpl template file.

Adding new pstpl template file. il y a 2 ans 8 mois #70392

  • mwilliams
  • Portrait de mwilliams
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
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.
Dernière édition: il y a 2 ans 8 mois par mwilliams.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Adding new pstpl template file. il y a 2 ans 8 mois #70410

  • Mazi
  • Portrait de Mazi
  • Hors ligne
  • LimeSurvey Team
  • Messages : 5324
  • Remerciements reçus 294
  • Karma: 249
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)limesurvey.org'"
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Adding new pstpl template file. il y a 2 ans 8 mois #70428

  • mwilliams
  • Portrait de mwilliams
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
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.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Adding new pstpl template file. il y a 2 ans 8 mois #70429

  • Mazi
  • Portrait de Mazi
  • Hors ligne
  • LimeSurvey Team
  • Messages : 5324
  • Remerciements reçus 294
  • Karma: 249
mwilliams écrit:
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)limesurvey.org'"
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Adding new pstpl template file. il y a 2 ans 8 mois #70430

  • mwilliams
  • Portrait de mwilliams
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
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).
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Adding new pstpl template file. il y a 2 ans 8 mois #70434

  • tpartner
  • Portrait de tpartner
  • En ligne
  • LimeSurvey Team
  • Messages : 4139
  • Remerciements reçus 767
  • Karma: 349
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Adding new pstpl template file. il y a 2 ans 8 mois #70467

  • mwilliams
  • Portrait de mwilliams
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
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.
Dernière édition: il y a 2 ans 8 mois par mwilliams.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Adding new pstpl template file. il y a 2 ans 8 mois #70470

  • tpartner
  • Portrait de tpartner
  • En ligne
  • LimeSurvey Team
  • Messages : 4139
  • Remerciements reçus 767
  • Karma: 349
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Adding new pstpl template file. il y a 1 an 2 mois #96924

  • joss
  • Portrait de joss
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
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
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Adding new pstpl template file. il y a 1 an 2 mois #96925

  • joss
  • Portrait de joss
  • Hors ligne
  • Fresh Lemon
  • Messages : 16
  • Karma: 0
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
L'administrateur a désactivé l'accès en écriture pour le public.
  • Page :
  • 1
  • 2
Modérateurs: ITEd
Temps de génération de la page : 0.233 secondes
Donation Image