Page 1 of 1

How to use executable php in posts

Posted: Mon Jun 11, 2018 10:32 am
by elseman
I need to embed executable php code in posts. Is there any hack for it?

Re: How to use executable php in posts

Posted: Mon Jun 11, 2018 11:07 am
by Edi
You can modifiy an existing template or code your own one to use php code.

Re: How to use executable php in posts

Posted: Mon Jun 11, 2018 12:10 pm
by elseman
I want use different PHP code in different Bludit posts.
I need somethink like [exec] [/exec] tag, which will be interpreted as pure PHP.
This will allow to use custom PHP code on any page, as much times, as needed.

Re: How to use executable php in posts

Posted: Mon Jun 11, 2018 12:41 pm
by Edi
elseman wrote: Mon Jun 11, 2018 12:10 pm I want use different PHP code in different Bludit posts.
I need somethink like [exec] [/exec] tag, which will be interpreted as pure PHP.
This will allow to use custom PHP code on any page, as much times, as needed.
If you really need (?) [exec] [/exec] you have to use the heavy weight Content Management System (CMS) with this sort of code. Or write your own plugin.

As I wrote before you also can modify existing templates or code your own. This is easy for somebody who knows how to use PHP (otherwise also [exec] [/exec] makes no sense...).

Beside this, the fundamental concept of any CMS is to separate content from code and style.

Re: How to use executable php in posts

Posted: Mon Jun 11, 2018 1:09 pm
by elseman
I use heavyweight CMS, and there is no this feature too, I'm using workaround for WP, which takes 20 strings of code in 1 php file.

Maybe someone can write code better than us, and will share some?
Edi wrote: Mon Jun 11, 2018 12:41 pm
elseman wrote: Mon Jun 11, 2018 12:10 pm I want use different PHP code in different Bludit posts.
I need somethink like [exec] [/exec] tag, which will be interpreted as pure PHP.
This will allow to use custom PHP code on any page, as much times, as needed.
If you really need (?) [exec] [/exec] you have to use the heavy weight Content Management System (CMS) with this sort of code. Or write your own plugin.

As I wrote before you also can modify existing templates or code your own. This is easy for somebody who knows how to use PHP (otherwise also [exec] [/exec] makes no sense...).
yes, I really need. And as I wrote before, modifying template can't give this feature, that I need.

Re: How to use executable php in posts

Posted: Mon Jun 11, 2018 1:26 pm
by Edi
elseman wrote: Mon Jun 11, 2018 1:09 pm yes, I really need. And as I wrote before, modifying template can't give this feature, that I need.
In this case we have to know what the code executes, and why it is not possible using a template. And: Why PHP is needed and it cannot be done using JavaScript or jQuery.

By the way: You also can use iFrames as part of the content, despite it's not best practice.

Re: How to use executable php in posts

Posted: Mon Jun 11, 2018 2:30 pm
by elseman
Edi wrote: Mon Jun 11, 2018 1:26 pm In this case we have to know what the code executes, and why it is not possible using a template. And: Why PHP is needed and it cannot be done using JavaScript or jQuery.
the code executes wide range of tasks, from "hello world" and phpinfo(); to asking number of different API's and generating some output. It can not be implemented by using template, forget about it.

Iframes? Are you serious?

Re: How to use executable php in posts

Posted: Mon Jun 11, 2018 3:03 pm
by Edi
Again: Bludit is a CMS not a PHP framework. ;-)

If you are a developer it's no proplem to add own plugins.

In the documentation is also an example for a plugin to display "Hello World" in the sidebar:

https://docs.bludit.com/en/plugins/plug ... ello-world

Re: How to use executable php in posts

Posted: Mon Jun 11, 2018 3:35 pm
by bayerberg
you can do it automatically based on the category or tags of the page you want to spice up

categories - you can do it based on category name or slug. something as simple as

Code: Select all

          
          if ($page->category()) {
            if ($page->category()=="Category Name Here") {
             // your code here
            }
           }
or

Code: Select all

    
  if ($page->category()) {
            if ($page->categoryKey()=="cat-slug-here") {
            //your code here
            }
          };
tags - this might be a bit fiddly, if you have multiple tags with multiple scripts assigned to them there might be a bit of a mess if those scripts wont play nicely with each other. QA a must :)

Code: Select all

if ($page->tags()) {
  foreach ($tags as $tagKey=>$tagName) {
    if ($tagKey=="tag-slug-here") {
    // your code here
    }
  }
}