close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

php values in CMS content?

Thread begun 1/31/2016 11:20 am by Steve | Last modified 12/22/2016 12:36 am by Ray Borduin | 2532 views | 7 replies |

Steve

php values in CMS content?

Is there a way to allow dynamic content in Power CMS content? It seems that there are library pages and disable php values in stored content.

For instance, I am trying to put this code within some CMS content:

<?php if (($goldPrice)!='') { ?>
$<strong><?php echo $goldPrice; ?></strong> - <?php echo($Gold->getColumnVal("date")); ?><br />
<?php }
else {
echo 'N/A';
} ?>
Sign in to reply to this post

Ray BorduinWebAssist

You can't embed php code directly. I can help with a solution to that problem to allow it in a premier support ticket.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jason

Did you come up with a solution for this you could share, or will I need a premier support ticket to do this also?

Sign in to reply to this post

Steve

Not too sure as that was Jan 2016 :-)

Jasons back? Welcome back.

Sign in to reply to this post

Jason

Thanks for the quick reply Steve. Unfortunately no, Jason (Byrnes) isn't back. I'm just an average user named Jason. lol

Sign in to reply to this post

Ray BorduinWebAssist

Different Jason ;)

I think I had him use a placeholder in his code like: [goldprice] and then showed him how to use str_replace() to replace the placeholder with the php code on the page itself.

Sign in to reply to this post
Did this help? Tips are appreciated...

Jason

Original Ray ;)

Thanks!
I'm doing this right now and it's working:

php:
<?php

$dateMonth 
date('M');
$dateDay date('j');
$original = array("[dateMonth]""[dateDay]");
$new = array($dateMonth$dateDay);
?>
<?php 
echo str_replace($original$newWA_getCMSContent($database_PowerCMSConnection$PowerCMSConnection'Home''Calendar')); ?>



I'd really like to have a more dynamic solution though. I tried something like this where I replaced the php open and close tags in the database with "[{[{" and "]}]}". Then I did this:

php:
<?php

$original 
= array("[{[{""]}]}");
$new = array("<?php""?>");
?>
<?php 
echo str_replace($original$newWA_getCMSContent($database_PowerCMSConnection$PowerCMSConnection'Home''Calendar')); ?>



No luck though. Am I close to something here, or chasing the white rabbit?

Sign in to reply to this post

Ray BorduinWebAssist

It is more complex than that.

You could probably pull it off using the functions:

preg_match();
to find the php references and save them into an array.

and then:
eval()
to execute the php code and get the result

Then finally str_replace() to replace it.

It is worth noting that you will want to disable inline editing with either technique (yours or the more complex one) since any dynamic values would end up being replaced with their values as soon as the inline edits were saved.

I have gotten around this limitation to allow any dynamic value, but the solution becomes pretty complex. It involves using code like this for the placeholder:

<span class="php_replace" rel="$variablename">sample value</span>



Then I search through the code for anything with the "php_replace" class using preg_match() and when I replace it I only update the "sample value" portion and leave the rest of the tag intact. This way you can still use the inline editor, but if you replace the dynamic portion your edits are ignored and the value stays dynamic since you wouldn't ever actually remove the <span> and its class while editing.

Sign in to reply to this post
Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...