Forum
HTML Template with PHP code
Hello, is it possible to integrate a line of PHP code in my HTML Content Template ?
in the content Template, i have a Perch tag for a Persons Initials <perch:if exists="initials"> <a class="anker" name="<perch:content id="initials" type="text" label="Initialen" order="4" />"></a> </perch:if>
in the same template, i want to reuse the "initials" for a line of PHP to display some content from a database: <? lehrerPlan('INITIALS'); ?>
how can I do this ?
thank you, katja
~~~
Summary information
Perch: 2.8.24, PHP: 5.6.30, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (2.8.24), assets (2.8.24), categories (2.8.24), perch_mailchimp (2.0.1)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_mailchimp', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /homepages/12/d125864790/htdocs/studios/perch
PERCH_CORE: /homepages/12/d125864790/htdocs/studios/perch/core
PERCH_RESFILEPATH: /homepages/12/d125864790/htdocs/studios/perch/resources
Image manipulation: GD
PHP limits: Max upload 64M, Max POST 64M, Memory: 256M, Total max file upload: 64M
F1: dc1fef2ad0fcd9f943c02ebb43d85dbc
Resource folder writeable: Yes
HTTP_HOST: patrickbroome.de
DOCUMENT_ROOT: /kunden/homepages/12/d125864790/htdocs/studios
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
is there any way to
The best you can do in Perch 2 is call a layout from the template and put your code in that.
In Perch 3 you could turn it into a template filter.
thanks, i am glad there is a way where would i find this in the documentation ?
best regards ! katja
i found out how to refer to a layout PHP page
but i can't work out how to include the perch Tag into the layout page
<? lehrerPlan('XX'); ?>
when i put <perch:content id="initials" type="text" label="Initialen" /> in place of XX, it doesn't work ...
Sure, it's here: https://docs.grabaperch.com/templates/includes/layouts/
Thank you Drew, i found this
but now i can't work out how to include the perch Tag into the PHP layout page
<? lehrerPlan('XX'); ?>
when i put <perch:content id="initials" type="text" label="Initialen" /> in place of XX, it doesn't work ...
Katja,
In order to send variable to layout from template
in layout template use
to pass back into template use
thank you for your explanation, but i don't quite understand, as i am not a PHP programmer, sorry !
my perch Tag is <perch:content id="initialen" type="text" label="Initialen" order="4" />
so the users input from "initialen" would be my variable, right ?
when i send <perch:layout path="path_to_template.php" variable1="initialen" /> to layout PHP, it does not work
What happens?
it is printed "nope not there" - apparently, the value of the variable does not get there ?
it just doesnt work out ... how would i transfer the value from the content Tag, which is in the HTML template, to the layout PHP ?
i need to repleace xx with the value of "initials"
To use the layout, you'd have:
which would load in the file
perch/templates/layouts/mylayout.php
All your content variables will be passed to that layout as layout variables. So then you'd do:
Thank you Drew, for looking at this again,
but it still does not show up on the page, i am getting desperate
i did as you described, the path to the layout is correct, but the result is "nope"
that is the code from mylayout.php ~~~ <?php
if (perch_layout_has('initials')) { perch_layout_var('initials'); }else{ echo "Nope, not here!"; }
?>
You need to pass the variable to the layout
You don't, it's automatic.
Thank you very much Robert,
now it works
thanks for your patience and your great support
best regards ! katja
Drew, I don't want to be pain, I use layouts a lot and there is also this documentation on the perch site: Passing Variables into Layouts https://docs.grabaperch.com/perch/pages-and-nav/layouts/variables/
Without passing the variable as an attribute on the layout tag: Including Layouts in Templates https://docs.grabaperch.com/templates/includes/layouts/ "Any attributes set on the perch:layout tag are passed through as layout variables." I've not been able to discover them automatically there.
I have never seen documentation to the effect of this happening automatically, so I use the above documented approach.