Including php in a template

Post

Posted
Rating:
#3475 (In Topic #656)
Avatar
Standard member
crkgb is in the usergroup ‘Fan in action’
Hello,

Is there a way to include PHP inside a template. For example something like this

<?php require_once '/pcw/shortcode.php'; ?>

Thank you
Online now: No Back to the top

Post

Posted
Rating:
#3476
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
There's a hidden option you can enable via Commandr:

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.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#3477
Avatar
Standard member
crkgb is in the usergroup ‘Fan in action’
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.
Online now: No Back to the top

Post

Posted
Rating:
#3478
Avatar
Standard member
crkgb is in the usergroup ‘Fan in action’
I need to learn about this mini-blocks you are talking about. Is there a place I could read about those?
Online now: No Back to the top

Post

Posted
Rating:
#3479
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
Did the Commandr line take correctly? (i.e. no errors)
Did you edit your template after putting in the command?


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#3480
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
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.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#3481
Avatar
Standard member
crkgb is in the usergroup ‘Fan in action’
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.
Online now: No Back to the top

Post

Posted
Rating:
#3482
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
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]


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#3483
Avatar
Standard member
crkgb is in the usergroup ‘Fan in action’
Will try to play with it for a little while. Thank you Chtis
Online now: No Back to the top

Post

Posted
Rating:
#3484
Avatar
Standard member
crkgb is in the usergroup ‘Fan in action’
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?

Online now: No Back to the top

Post

Posted
Rating:
#3485
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
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.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#3486
Avatar
Standard member
crkgb is in the usergroup ‘Fan in action’
Got it, thank you
Online now: No Back to the top

Post

Posted
Rating:
#3487
Avatar
Standard member
crkgb is in the usergroup ‘Fan in action’
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';
Online now: No Back to the top

Post

Posted
Rating:
#3488
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
Probably:
require_once 'pcw/shortcode.php';

Composr sets the current working directory to the root.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
#3489
Avatar
Standard member
crkgb is in the usergroup ‘Fan in action’
Awesome, got everything to work. Thank you.
Online now: No Back to the top

Post

Posted
Rating:
#3963
Avatar
Standard member
ironfeather is in the usergroup ‘Well-settled’
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:
Composr Tutorial: Writing mini-modules - Composr

the same as a mini-block you are discussing in this post?

Thanks much

Stevyn

 

———–
Publisher of IronFeather Journal since 1987.  Host of KGNU Colorado Radio for 20 years. 
Currently in Japan & decided to focus on Composr as my number one CMS.
Composr site for community of Hokkaido:  Nandalow.com
Composr site for my freelance work: Futurecode.jp
My Compsr edits : 
http://ironfeather.com/bbs/viewtopic.php?f=12&t=2862
Twitter: https://twitter.com/futurecodejp

 
Online now: No Back to the top

Post

Posted
Rating:
#3964
Avatar
Site staff
Adam Edington is in the usergroup ‘Super-moderators’
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.
Online now: No Back to the top

Post

Posted
Rating:
#3965
Avatar
Standard member
ironfeather is in the usergroup ‘Well-settled’
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     :)

 

———–
Publisher of IronFeather Journal since 1987.  Host of KGNU Colorado Radio for 20 years. 
Currently in Japan & decided to focus on Composr as my number one CMS.
Composr site for community of Hokkaido:  Nandalow.com
Composr site for my freelance work: Futurecode.jp
My Compsr edits : 
http://ironfeather.com/bbs/viewtopic.php?f=12&t=2862
Twitter: https://twitter.com/futurecodejp

 
Online now: No Back to the top

Post

Posted
Rating:
#3967
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
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.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top
1 guest and 0 members have just viewed this.

Statistics

Forum statistics:
  • 2,050 topics, 7,193 posts, 10,823 members
  • Our newest member is devsphere
Birthdays:
Back to Top