Forum
Template includes
I've just upgrade a site to Perch 3 (Runway) and I think it has stopped template includes being referenced…
I have a template that includes an svg, for example:
<perch:template path="layouts/svg/transform.svg" />
and it works ok if I replace that with the svg code itself, but when it's an included file it's not appearing on the page. I've tried it with a few different file formats (.txt, .html, .php) in case it was .svg that it wasn't enjoying, but no joy. It was working fine until the upgrade, if that's any help.
Here are my diagnostics:
Summary information
Perch Runway: 3.0.2, PHP: 7.0.13, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (3.0.2), assets (3.0.2), categories (3.0.2), perch_blog (5.5.1), perch_forms (1.9)
App runtimes: <?php $apps_list = [ 'perch_blog', 'perch_forms', ];
PERCH_LOGINPATH: /cms
PERCH_PATH: /Users/TemperTemper/Sites/Gospelware/gospelware.co.uk/web/cms
PERCH_CORE: /Users/TemperTemper/Sites/Gospelware/gospelware.co.uk/web/cms/core
PERCH_RESFILEPATH: /Users/TemperTemper/Sites/Gospelware/gospelware.co.uk/web/cms/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
HTTP_HOST: gospelware.local
DOCUMENT_ROOT: /Users/TemperTemper/Sites/Gospelware/gospelware.co.uk/web
REQUEST_URI: /cms/core/settings/diagnostics/
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php
What does debug have to say about it?
Hope that helps…
Does it help?
Is it automatically adding an
.html
extension? It used to be ok with svg, didn't it? Or was that a bug that has been fixed in v3? If so I've got a lot of refactoring to do before I upgrade any more sites to v3…Templates are
.html
files, so I'm not quite sure what you're doing.It looks like two things, according to that file path from the debug:
perch:template
Up until upgrading I had been referencing .svg files using
perch:template
and it worked ok.I was using perch/templates/ as the root too, so I was able to reference SVG files in the perch/templates/layouts/ directory too (I was referencing these in both layouts/pages and in content templates), meaning I only had to have one SVG file that could be referenced from anywhere. Actually the docs say:
so that might be a bug.
On the file extension front, I guess that must've been me inadvertently taking advantage of a bug that was fixed in version 3.
Is there any chance you could officially allow .svg files to be referenced in a
perch:template
tag (SVG being a sort of subset of HTML anyway)…?Actually, thinking about allowed filetypes, it would be super cool to allow .txt files and maybe even .md file too… (I mentioned .php in my initial question – that was an oversight because of course .php wouldn't render in a template… Sorry if that was misleading!)
If it has to be .html, let me know and I'll go through all my sites and change all of the .svg files a .html extension instead.
If you want to include PHP you can use a layout tag for that.
perch:template
tags are intended for including sub templates. If you're relying on some undefined behaviour that has now changed, I'm not sure that's entirely my fault.I'll see if we have find a way to accommodate that sort of use without breaking the defined behaviour for everyone else.
Yeah, sorry about mentioning the php thing. Just confused things.
Certainly no blame thrown on the change in behaviour – I think I was exploiting a bug and thinking it was normal behaviour :) Not your fault at all that it's doing only the thing it was intended to do now :D But thanks for having a look to see whether you can accommodate it – it'd save me a lot of work, so fingers crossed you can manage it without breaking anything for everyone else.
The template path thing might be an issue though – if people have followed the docs and included /content/ in their defined file path it'll be going to perch/templates/content/content/blah and probably not finding the file. That's why my filepath was going to perch/templates/content/layouts/ – I had defined /layouts/ in my
perch:template
tag's fiepath:<perch:template path="layouts/svg/transform.svg" />
Hi Drew,
I've just come to update another website before doing some dev and it looks like both of the issues tied to this thread are still alive. The file path is still going to perch/templates/content/ rather than in perch/templates/, as the documentation outlines.
My debug is telling me:
Where it should be going to
Sorry to be a bit of a broken record on this one, but I'm chomping at the bit to upgrade my clients' sites to v3… I had to roll that website from last month back to 2.8.34 and I haven't updated any other client websites to v3 yet because of the filepath thing :'(
Also really hoping that you're able to get .svg extensions working inside templates, svg being basically html… Can't tell you how much work that would save me. You'll be able to see what I mean from the line from the debug above – it's appending .html to the filepath automatically, by the looks of it. In case it helps, I tried removing the file extension from the include completely
<perch:template path="layouts/svg/twitter" />
and it added.html
, and I added .html to the include<perch:template path="layouts/svg/twitter.html" />
and it didn't add it twice.Thanks for taking a look,
Martin.
It's logged, so we should get to it before long.
Great stuff. I'll work around with this site and keep an eye on the release notes. Thanks Drew :)