This is a discussion on PHP newbie (generating HTML content in a generic way)- HOW ? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Sorry for the crossposting - I'm not sure which is the most active/relevant php ng yet .... Hi, I am ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Sorry for the crossposting - I'm not sure which is the most
active/relevant php ng yet .... Hi, I am a PHP newbie, but have been programming C/C++ for over 10 years, so in that respect, I'm not a programming noob. I am putting together a few web pages and I want to 'modularize' the page content into 'blocks', so that I have php script responsible for creating different blocks - e.g. header.php (responsible for creating header section) footer.php (responsible for creating footer section) lhsnavig.php (responsible for creating lefthandside menu navigation section) etc .... can some one please provide me with skeleton code that I can use to create such a 'framework' ? MTIA |
|
|||
|
Ronald Raygun a écrit :
> can some one please provide me with skeleton code that I can use to > create such a 'framework' ? MTIA Smarty is an easy one, not really a framework, it's a template engine which can help you with your request. http://www.smarty.net/ Regards, -- Guillaume |
|
|||
|
Guillaume wrote: > Ronald Raygun a écrit : > >> can some one please provide me with skeleton code that I can use to >> create such a 'framework' ? MTIA > > > Smarty is an easy one, not really a framework, it's a template engine > which can help you with your request. > > http://www.smarty.net/ > > Regards, Hi Guillame, I know about smarty - even though its quite 'lightweight', its too much of an overhead (not to mention leaning curve) for what I want to do, which is create little scripts, each of which generates a 'block' of html code - and then combining all of the little 'blocks' of html into an html code. This way, I can easily and quickly, build little libraries (PHP scripts), each of which builds specific html 'blocks', e.g. navigation menus etc, so I can quickly put a page together using these blocks. The problem is not how to write the script that generates the html (thats basically a case of using the echo statement), its how I can use those 'little blocks' in a single page - this will save me typing the same text over and over in my pages - and also reduce possibility of error, provide code resuse etc, etc... |
|
|||
|
On Apr 10, 12:35 pm, Ronald Raygun <inva...@domain.com> wrote:
> Guillaume wrote: > > Ronald Raygun a écrit : > > >> can some one please provide me with skeleton code that I can use to > >> create such a 'framework' ? MTIA > > > Smarty is an easy one, not really a framework, it's a template engine > > which can help you with your request. > > >http://www.smarty.net/ > > > Regards, > > Hi Guillame, > > I know about smarty - even though its quite 'lightweight', its too much > of an overhead (not to mention leaning curve) for what I want to do, > which is create little scripts, each of which generates a 'block' of > html code - and then combining all of the little 'blocks' of html into > an html code. > > This way, I can easily and quickly, build little libraries (PHP > scripts), each of which builds specific html 'blocks', e.g. navigation > menus etc, so I can quickly put a page together using these blocks. > > The problem is not how to write the script that generates the html > (thats basically a case of using the echo statement), its how I can use > those 'little blocks' in a single page - this will save me typing the > same text over and over in my pages - and also reduce possibility of > error, provide code resuse etc, etc... <http://www.php.net/include> |
|
|||
|
*** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 17:35:09 +0100):
> The problem is not how to write the script that generates the html > (thats basically a case of using the echo statement), its how I can use > those 'little blocks' in a single page - this will save me typing the > same text over and over in my pages - and also reduce possibility of > error, provide code resuse etc, etc... If you mean blocks like headers, footers, navigation bars... I've always kept them in individual files inside a directory called "inc" (for "included files", since I insert them with the PHP include construct). They're typically plain HTML with some PHP bits inside. <div id="footer"> <p>© 2008 by John Smith, generated on <?=date('d/m/y')?>, blah blah</p> <p>More blah blah.</p> </div> My site pages have a very basic skeleton (all design goes in *.css and *.inc.php files): <? $title = 'Template'; require($_SERVER['DOCUMENT_ROOT'] . '/inc/config.inc.php'); ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="es"> <head><title>borrame.com ¤ <?=htmlspecialchars($title)?></title> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/head.inc.php') ?> <body> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php') ?> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/menu.inc.php') ?> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/options.inc.php') ?> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/recommended.inc.php') ?> <div id=content> <h1><?=htmlspecialchars($title></h1> <? codigo('__plantilla.sql') ?> <p>Here comes content.</p> </div> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php') ?> </body> </html> -- -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain -- Mi sitio sobre programación web: http://bits.demogracia.com -- Mi web de humor en cubitos: http://www.demogracia.com -- |
|
|||
|
Álvaro G. Vicario wrote: > *** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 17:35:09 +0100): > >>The problem is not how to write the script that generates the html >>(thats basically a case of using the echo statement), its how I can use >>those 'little blocks' in a single page - this will save me typing the >>same text over and over in my pages - and also reduce possibility of >>error, provide code resuse etc, etc... > > > If you mean blocks like headers, footers, navigation bars... I've always > kept them in individual files inside a directory called "inc" (for > "included files", since I insert them with the PHP include construct). > They're typically plain HTML with some PHP bits inside. > > > <div id="footer"> > <p>© 2008 by John Smith, generated on <?=date('d/m/y')?>, blah blah</p> > <p>More blah blah.</p> > </div> > > > My site pages have a very basic skeleton (all design goes in *.css and *.inc.php files): > > > <? > > $title = 'Template'; > > require($_SERVER['DOCUMENT_ROOT'] . '/inc/config.inc.php'); > > ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> > <html lang="es"> > <head><title>borrame.com ¤ <?=htmlspecialchars($title)?></title> > <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/head.inc.php') ?> > <body> > > <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php') ?> > <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/menu.inc.php') ?> > <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/options.inc.php') ?> > <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/recommended.inc.php') ?> > > <div id=content> > > > <h1><?=htmlspecialchars($title></h1> > > <? codigo('__plantilla.sql') ?> > > <p>Here comes content.</p> > > </div> > > <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php') ?> > > </body> > </html> > > > > > Thanks Álvaro, this looks like EXACTLY what I was looking for. By the way, what is the codigo() function used for ? (is it a spanish word or a PHP keyword)? |
|
|||
|
Ronald Raygun wrote:
> > > �lvaro G. Vicario wrote: >> *** Ronald Raygun escribi�/wrote (Thu, 10 Apr 2008 17:35:09 +0100): >> >>> The problem is not how to write the script that generates the html >>> (thats basically a case of using the echo statement), its how I can >>> use those 'little blocks' in a single page - this will save me typing >>> the same text over and over in my pages - and also reduce possibility >>> of error, provide code resuse etc, etc... >> >> >> If you mean blocks like headers, footers, navigation bars... I've always >> kept them in individual files inside a directory called "inc" (for >> "included files", since I insert them with the PHP include construct). >> They're typically plain HTML with some PHP bits inside. >> >> >> <div id="footer"> >> <p>© 2008 by John Smith, generated on <?=date('d/m/y')?>, >> blah blah</p> >> <p>More blah blah.</p> >> </div> >> >> >> My site pages have a very basic skeleton (all design goes in *.css and >> *.inc.php files): >> >> >> <? >> >> $title = 'Template'; >> >> require($_SERVER['DOCUMENT_ROOT'] . '/inc/config.inc.php'); >> >> ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" >> "http://www.w3.org/TR/html4/strict.dtd"> >> <html lang="es"> >> <head><title>borrame.com ¤ <?=htmlspecialchars($title)?></title> >> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/head.inc.php') ?> >> <body> >> >> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php') ?> >> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/menu.inc.php') ?> >> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/options.inc.php') ?> >> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/recommended.inc.php') ?> >> >> <div id=content> >> >> >> <h1><?=htmlspecialchars($title></h1> >> >> <? codigo('__plantilla.sql') ?> >> >> <p>Here comes content.</p> >> >> </div> >> >> <? include($_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php') ?> >> >> </body> >> </html> >> >> >> >> >> > > Thanks �lvaro, this looks like EXACTLY what I was looking for. By the > way, what is the codigo() function used for ? (is it a spanish word or a > PHP keyword)? Not to speak for the poster Vicario or anything here, but codigo() could be a user-defined function defined in one of the many include()ed source code files.... The parameter passed to the function is quite possibly a reference to an SQL script to execute when the function is called.... ...gk |
|
|||
|
*** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 22:45:17 +0100):
> Thanks Álvaro, this looks like EXACTLY what I was looking for. By the > way, what is the codigo() function used for ? (is it a spanish word or a > PHP keyword)? It's a custom function I use in the site the sample comes from. I just forgot to remove it <:-) -- -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain -- Mi sitio sobre programación web: http://bits.demogracia.com -- Mi web de humor en cubitos: http://www.demogracia.com -- |
|
|||
|
I do something similar. In addition, you can create functions and
call them at various points in the page to insert content of all sorts along with appropriate html and tags, style attributes and javascript. Using a master function with a switch operator, you can vary the template, location of content in the page and other variables. I actually found it was easier to set this up myself than to learn Smarty, which looked like a challenge. I'm really happy with what I have and can customize it to do exactly what I want it to do. --Kenoli On Apr 11, 8:40*am, "Álvaro G. Vicario" <webmasterNOSPAMTHA...@demogracia.com> wrote: > *** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 22:45:17 +0100): > > > Thanks Álvaro, this looks like EXACTLY what I was looking for. By the > > way, what is the codigo() function used for ? (is it a spanish word or a > > PHP keyword)? > > It's a custom function I use in the site the sample comes from. I just > forgot to remove it <:-) > > -- > --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain > -- Mi sitio sobre programación web:http://bits.demogracia.com > -- Mi web de humor en cubitos:http://www.demogracia.com > -- |
|
|||
|
kenoli wrote:
> On Apr 11, 8:40 am, "Álvaro G. Vicario" > <webmasterNOSPAMTHA...@demogracia.com> wrote: >> *** Ronald Raygun escribió/wrote (Thu, 10 Apr 2008 22:45:17 +0100): >> >>> Thanks Álvaro, this looks like EXACTLY what I was looking for. By the >>> way, what is the codigo() function used for ? (is it a spanish word or a >>> PHP keyword)? >> It's a custom function I use in the site the sample comes from. I just >> forgot to remove it <:-) >> >> -- >> --http://alvaro.es- Álvaro G. Vicario - Burgos, Spain >> -- Mi sitio sobre programación web:http://bits.demogracia.com >> -- Mi web de humor en cubitos:http://www.demogracia.com >> -- > > > I do something similar. In addition, you can create functions and > call them at various points in the page to insert content of all sorts > along with appropriate html and tags, style attributes and > javascript. Using a master function with a switch operator, you can > vary the template, location of content in the page and other > variables. I actually found it was easier to set this up myself than > to learn Smarty, which looked like a challenge. > > I'm really happy with what I have and can customize it to do exactly > what I want it to do. > > --Kenoli > (Top posting fixed) Much better than using a switch() function is to use classes - or different functions to do different things. Never have one function do multiple things - like output different HTML based on a switch() statement. It makes troubleshooting a nightmare. P.S. Please don't top post. Thanks. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
![]() |
| Thread Tools | |
| Display Modes | |
|
|