How to use executable php in posts

Post Reply
User avatar
elseman
Jr. Bludit
Posts: 4
Joined: Mon Jun 11, 2018 10:25 am

I need to embed executable php code in posts. Is there any hack for it?
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

You can modifiy an existing template or code your own one to use php code.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
elseman
Jr. Bludit
Posts: 4
Joined: Mon Jun 11, 2018 10:25 am

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.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
elseman
Jr. Bludit
Posts: 4
Joined: Mon Jun 11, 2018 10:25 am

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.
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
elseman
Jr. Bludit
Posts: 4
Joined: Mon Jun 11, 2018 10:25 am

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?
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
bayerberg
Master Bludit
Posts: 141
Joined: Wed Jun 07, 2017 1:05 pm
Location: London, UK
Has thanked: 7 times
Been thanked: 10 times
Contact:

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
    }
  }
}
bludit plugins and themes - makeitblu | I do things, check them out on behance and dribbble.
Post Reply