Including php in a template
Posted
#3469
(In Topic #687)
Is there a way to include PHP inside a template. For example something like this
<?php require_once '/pcw/shortcode.php'; ?>
Thank you
Posted
Code
:set_value('allow_php_in_templates', '1');
However I would not recommend it, as you're granting any theme you install in the future permission to run PHP code on your server.
You are better off writing and including a mini-block.
Posted
I added the line you provided. Is there any special tags php needs to be wrapped into. Straight up is not working.
Posted
Posted
Did you edit your template after putting in the command?
Posted
That said, that code would need to be compatible - if it's pulled from some Wordpress addon it's almost certainly not going to work, it would need to be standalone PHP.
Posted
I guess the correct question I should have asked. Let's say I am creating a news article. Is there a way to include php in there?
Pretty sure the template will accept php after the command line addition, but that's not what I intended on asking.
Posted
You can easily include it via a block in Comcode.
Put your PHP code in sources_custom/miniblocks/shortcode.php
and include with [block]shortcode[/block]
Posted
require_once '../pcw/shortcode.php';
So how do I call what I need into the [block]shortcode[/block] so that my php file is included in there? Is it a file name I have in the folder?
Posted
Posted
So if my needed folder is in the public_html directory along with all composr folders. lets say called pcw.
What path do I use in my block for sources_custom/miniblocks
What do I need to change below?
require_once '../pcw/shortcode.php';
Posted
require_once 'pcw/shortcode.php';
Composr sets the current working directory to the root.
Posted
I am creating some PHP scripts for my co-workers to make their daily chores easier and now after reading this post I realize I can embed these tools into a COMPOSR and really make it look awesome!
I am wondering though, is a mini-module as talked about here:
the same as a mini-block you are discussing in this post?
Thanks much
Stevyn
Posted
Posted
thinking I will try it first as a mini-module as it is pulling in many things to process. Basically it does a GIT clone, then some edits and a GIT push back. and some other items.
geeking out to try it tomorrow when back at the office :)
Posted
Mini-blocks and mini-modules are implemented in exactly the same way, i.e. you just code a pure PHP file without any real forced structure but have full access to Composr's API. Just a mini-block is a block and a mini-module is a module (a page, i.e. accessed by URL).
They are stored in different directories, sources_custom/miniblocks vs <zone>/pages/minimodules_custom.
14 guests and 0 members have recently viewed this.
