Including php in a template
Hello,
Is there a way to include PHP inside a template. For example something like this
<?php require_once '/pcw/shortcode.php'; ?>
Thank you
Is there a way to include PHP inside a template. For example something like this
<?php require_once '/pcw/shortcode.php'; ?>
Thank you
There's a hidden option you can enable via Commandr:
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.
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.
I'm gonna try to lay with the commandr first I thin.
I added the line you provided. Is there any special tags php needs to be wrapped into. Straight up is not working.
I added the line you provided. Is there any special tags php needs to be wrapped into. Straight up is not working.
I need to learn about this mini-blocks you are talking about. Is there a place I could read about those?
Did the Commandr line take correctly? (i.e. no errors)
Did you edit your template after putting in the command?
Did you edit your template after putting in the command?
I just tested and it worked ok. But maybe your PHP could be wrong too. /pcw looks suspicious, because I highly doubt you have the folder on the drive root. Maybe needs to be <?php require_once get_file_base() . '/pcw/shortcode.php'; ?>.
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.
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.
It took it fine. I think I am the one who is messed up here.
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.
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.
Oh right. So into Comcode. No, that wouldn't work. We recognise PHP tags in pure Tempcode, but not Comcode.
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]
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]
Will try to play with it for a little while. Thank you Chtis
It works like this for me
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?
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?
In my example sources_custom/miniblocks/shortcode.php is a PHP file, creating a block called shortcode. It's just a normal PHP file that you can put code in - either the direct code you want, or a require_once line like you were wanting to use directly.
Got it, thank you
Ok,struggling a bit.
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';
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';
Probably:
require_once 'pcw/shortcode.php';
Composr sets the current working directory to the root.
require_once 'pcw/shortcode.php';
Composr sets the current working directory to the root.
Awesome, got everything to work. Thank you.
Hello,
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
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
I believe miniblocks are aimed at simple scripts that reside in a single file and minimodules are for more complex addons. You could do it either way, but one way likely makes more sense over the other depending on what you're aiming to achieve.
Tomorrow I will give it a go and report back
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 :)
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 :)
Hi,
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.
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.
1 guest and 0 members have recently viewed this.
