Jump to content


Photo

How to use macros (code templates) in PHP?


  • Please log in to reply
4 replies to this topic

#1 gig

gig
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 14 March 2006 - 05:06 PM

How I can use macros in PHP code - the goal is to substitute %piece1 with block of code or function call. I need for following task - to include different piece of code based on situation. Thanks in advance.

#2 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 14 March 2006 - 09:25 PM

[!--quoteo(post=354950:date=Mar 14 2006, 05:06 PM:name=gig)--][div class=\'quotetop\']QUOTE(gig @ Mar 14 2006, 05:06 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
How I can use macros in PHP code - the goal is to substitute %piece1 with block of code or function call. I need for following task - to include different piece of code based on situation. Thanks in advance.
[/quote]

if ($condition) {
  include ("grandma");
} else {
  include ("grandpa");
}

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#3 gig

gig
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 15 March 2006 - 03:11 PM

[!--quoteo(post=355059:date=Mar 14 2006, 04:25 PM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 14 2006, 04:25 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if ($condition) {
  include ("grandma");
} else {
  include ("grandpa");
}
[/quote]

Dear keeB,

1. Thank you.

2. I think, I asked wrong - what I really need is to use not runtime variables (like you suggested) but MACROS (by stating this I assumed like parser/preprocessor). So, last night I did some research via search engines and found that some preprocessor software exists that could possible help me with this.

I raised question because I am not programmer (in PHP or so) - I just bought CMS where php mixed with html and I realized that in order to separate my own additions (in design or so)
from existing CMS code I need some parser/preprocessor to keep all organized.

3. So, if you have some experience in such things, please help me sharing with. Anyway, looks like i need preprocessor software for my purpose.

Best regards, Ian

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 15 March 2006 - 05:30 PM

What your looking for sounds more like a templating system. If the CMS you have doesn't have one then it would be pretty difficult to encorperate without knowing php, but there are plenty of templating engines around. Some simple, some quite advanced.

#5 gig

gig
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 17 March 2006 - 07:08 AM

[!--quoteo(post=355405:date=Mar 15 2006, 12:30 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Mar 15 2006, 12:30 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What your looking for sounds more like a templating system. If the CMS you have doesn't have one then it would be pretty difficult to encorperate without knowing php, but there are plenty of templating engines around. Some simple, some quite advanced.
[/quote]

Well, CMS I got has templating system (and macros - as its written on PHP) already. Plus studying PHP a little last night I found way how to add additional conditional inserts via PHP functions calls in my CMS - like what you suggested in the beginning.

And finally I found the solution - this is PPWizard - preprocessor that have enough power to cover my needs.

Big thanks for last link ;-)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users