Difficulties with custom fields

Post Reply
Sergelie
Sr. Bludit
Posts: 32
Joined: Sun Feb 14, 2021 3:19 pm
Has thanked: 6 times
Been thanked: 4 times
Contact:

I am experimenting with an example provided in the Bludit documentation.

Setting up custom fields worked well, but I have trouble posting the content in pages.

When I try to get the custom field value example - pasting this code in the source (using TinyMCE):

Code: Select all

<?php
    if ($page->custom('inStock')) {
        echo "There is stock!";
    } else {
        echo "No more products";
    }
?>
TinyMCE saves:

Code: Select all

<!--?php 
    if ($page-&gt;custom('inStock')) {
        echo "There is stock!";
    } else {
        echo "No more products";
    }
?-->
So it looks like TinyMCE diseable the code. Although, in TinyMCE config I use the protect feature - 3r line (php):

Code: Select all

 protect: [
        /\<\/?(if|endif)\>/g, // Protect <if> & </endif>
        /\<xsl\:[^>]+\>/g, // Protect <xsl:...>
        /<\?php.*?\?>/g
    ],
Any hints of what I could do to make this works? Thanks in advance.
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:

Neither TinyMCE (or EasyMDE) nor Bludit executes PHP code in the editor field.

It makes sense not to mix up content, style and code. ;)
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
Sergelie
Sr. Bludit
Posts: 32
Joined: Sun Feb 14, 2021 3:19 pm
Has thanked: 6 times
Been thanked: 4 times
Contact:

Alright, then, where should I paste the php code Edi?
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:

Sergelie wrote: Mon May 24, 2021 5:17 pm Alright, then, where should I paste the php code Edi?
In the template of the theme.
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
Sergelie
Sr. Bludit
Posts: 32
Joined: Sun Feb 14, 2021 3:19 pm
Has thanked: 6 times
Been thanked: 4 times
Contact:

After learning how to use the custom fields parser, I managed to do what I wanted to do (using the {{ field-name }} insert method - not that simple to understand. I learned the hard way that the name of the field should be written in small caps with a space before and after - {{ name }}.

The custom fields data is stored in a dbase, not with the text file itself. So is there a way to save only those fields (without resaving the whole page)? or a way to disable the text editor form save?

(I am trying to prevent mistakes when my customers do some minor editing themselves - they will only change custom fields values).
Post Reply