can one make a php function or macro with arguments to generate HTML code? [message #181771] |
Sat, 01 June 2013 10:21 |
steve nospam
Messages: 11 Registered: May 2013
Karma: 0
|
Junior Member |
|
|
I am newbie. I am writing HTML and find myself duplicating lots of
code, which is the same except for 1 or 2 names/items in it.
I do not know how to make a function or macro that takes arguments in
HTML or CSS. Then I read that php is much more powerful and one should
code HTML pages in php.
Here is an example of what I have, I am just asking for a hint or a
link on how to code this in php.
<div class="blabla">
<video poster="folder_name/image.png" controls>
<source src="folder_name/movie.ogv" type="video/ogg">
<source src="folder_name/movie.mp4" type="video/mp4">
opps, browser does not support the video tag.
</video>
</div>
The above block of HTML close is repeated many time. Each time, a
different "folder_name" is used.
So I end up copy/paste and edit this code many many times.
It would be nice if I can define a function, and just pass it the
folder_name and it returns back this whole code. So the above becomes
<div class="name">
make_video_code("ABC")
</div>
<div class="name">
make_video_code("ADR")
</div>
<div class="name">
make_video_code("ACB")
</div>
etc.... you get the idea.
Is something like this possible? Does any one have a templates or
example of how to do this in php? where to put the function
make_video_code()?
thanks
Steve
|
|
|
Re: can one make a php function or macro with arguments to generate HTML code? [message #181773 is a reply to message #181771] |
Sat, 01 June 2013 10:42 |
Luuk
Messages: 329 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 01-06-2013 12:21, steve nospam wrote:
> I am newbie. I am writing HTML and find myself duplicating lots of
> code, which is the same except for 1 or 2 names/items in it.
>
> I do not know how to make a function or macro that takes arguments in
> HTML or CSS. Then I read that php is much more powerful and one should
> code HTML pages in php.
>
> Here is an example of what I have, I am just asking for a hint or a
> link on how to code this in php.
>
> <div class="blabla">
> <video poster="folder_name/image.png" controls>
> <source src="folder_name/movie.ogv" type="video/ogg">
> <source src="folder_name/movie.mp4" type="video/mp4">
> opps, browser does not support the video tag.
> </video>
> </div>
>
> The above block of HTML close is repeated many time. Each time, a
> different "folder_name" is used.
> So I end up copy/paste and edit this code many many times.
>
> It would be nice if I can define a function, and just pass it the
> folder_name and it returns back this whole code. So the above becomes
>
> <div class="name">
> make_video_code("ABC")
> </div>
>
> <div class="name">
> make_video_code("ADR")
> </div>
>
> <div class="name">
> make_video_code("ACB")
> </div>
>
> etc.... you get the idea.
>
> Is something like this possible? Does any one have a templates or
> example of how to do this in php? where to put the function
> make_video_code()?
>
> thanks
> Steve
>
I would also include the 'div' inside the function, like this (untested):
function make_video_code($class, $video) {
echo "<div class=${class}>";
echo "<video poster="folder_name/image.png" controls>";
echo "<source src="folder_name/${video}.ogv" type="video/ogg">"
echo "</video>";
echo "</div>";
}
makevideo("name", "ABC");
makevideo("name", "ADR");
makevideo("different_class", "ACB");
|
|
|
Re: can one make a php function or macro with arguments to generate HTML code? [message #181774 is a reply to message #181773] |
Sat, 01 June 2013 10:57 |
Luuk
Messages: 329 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 01-06-2013 12:42, Luuk wrote:
> On 01-06-2013 12:21, steve nospam wrote:
>> I am newbie. I am writing HTML and find myself duplicating lots of
>> code, which is the same except for 1 or 2 names/items in it.
>>
>> I do not know how to make a function or macro that takes arguments in
>> HTML or CSS. Then I read that php is much more powerful and one should
>> code HTML pages in php.
>>
>> Here is an example of what I have, I am just asking for a hint or a
>> link on how to code this in php.
>>
>> <div class="blabla">
>> <video poster="folder_name/image.png" controls>
>> <source src="folder_name/movie.ogv" type="video/ogg">
>> <source src="folder_name/movie.mp4" type="video/mp4">
>> opps, browser does not support the video tag.
>> </video>
>> </div>
>>
>> The above block of HTML close is repeated many time. Each time, a
>> different "folder_name" is used.
>> So I end up copy/paste and edit this code many many times.
>>
>> It would be nice if I can define a function, and just pass it the
>> folder_name and it returns back this whole code. So the above becomes
>>
>> <div class="name">
>> make_video_code("ABC")
>> </div>
>>
>> <div class="name">
>> make_video_code("ADR")
>> </div>
>>
>> <div class="name">
>> make_video_code("ACB")
>> </div>
>>
>> etc.... you get the idea.
>>
>> Is something like this possible? Does any one have a templates or
>> example of how to do this in php? where to put the function
>> make_video_code()?
>>
>> thanks
>> Steve
>>
>
> I would also include the 'div' inside the function, like this (untested):
>
> function make_video_code($class, $video) {
> echo "<div class=${class}>";
> echo "<video poster="folder_name/image.png" controls>";
> echo "<source src="folder_name/${video}.ogv" type="video/ogg">"
> echo "</video>";
> echo "</div>";
> }
>
> makevideo("name", "ABC");
> makevideo("name", "ADR");
> makevideo("different_class", "ACB");
>
>
hmm, luckily i wrote '*untested*'
there's a ';' missing, and the function-name on the last 3 lines is
wrong.........
|
|
|
Re: can one make a php function or macro with arguments to generate HTML code? [message #181776 is a reply to message #181771] |
Sat, 01 June 2013 13:10 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 6/1/2013 6:21 AM, steve nospam wrote:
> I am newbie. I am writing HTML and find myself duplicating lots of
> code, which is the same except for 1 or 2 names/items in it.
>
> I do not know how to make a function or macro that takes arguments in
> HTML or CSS. Then I read that php is much more powerful and one should
> code HTML pages in php.
>
> Here is an example of what I have, I am just asking for a hint or a
> link on how to code this in php.
>
> <div class="blabla">
> <video poster="folder_name/image.png" controls>
> <source src="folder_name/movie.ogv" type="video/ogg">
> <source src="folder_name/movie.mp4" type="video/mp4">
> opps, browser does not support the video tag.
> </video>
> </div>
>
> The above block of HTML close is repeated many time. Each time, a
> different "folder_name" is used.
> So I end up copy/paste and edit this code many many times.
>
> It would be nice if I can define a function, and just pass it the
> folder_name and it returns back this whole code. So the above becomes
>
> <div class="name">
> make_video_code("ABC")
> </div>
>
> <div class="name">
> make_video_code("ADR")
> </div>
>
> <div class="name">
> make_video_code("ACB")
> </div>
>
> etc.... you get the idea.
>
> Is something like this possible? Does any one have a templates or
> example of how to do this in php? where to put the function
> make_video_code()?
>
> thanks
> Steve
>
Steve,
Yes, when working with HTML, there is a lot of duplication of HTML and
CSS. That's how things are.
As Luuk said, you can do it in PHP. But in reality, how much are you
going to save? You'll have to copy/paste the PHP code instead of the
HTML, and your code (which is basically static).
Maybe a better solution would be to use an editor which support macros.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|
Re: can one make a php function or macro with arguments to generate HTML code? [message #181777 is a reply to message #181776] |
Sat, 01 June 2013 13:23 |
steve nospam
Messages: 11 Registered: May 2013
Karma: 0
|
Junior Member |
|
|
On Jun 1, 8:10 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> As Luuk said, you can do it in PHP. But in reality, how much are you
> going to save? You'll have to copy/paste the PHP code instead of the
> HTML, and your code (which is basically static).
>
> Maybe a better solution would be to use an editor which support macros.
>
Good idea! why do the php processing each time, if it can be done
once.
I thought about this after posting the question, that now the server
has to do this string replacement each time the page is called, which
is silly actually.
What do recommend for this "macro" part? I use notepad now
and it does not have many features. do you one which is HTML/php/
javascript
friendly? so many editors and will take long time to try them all.
|
|
|
Re: can one make a php function or macro with arguments to generate HTML code? [message #181780 is a reply to message #181777] |
Sat, 01 June 2013 14:16 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 6/1/2013 9:23 AM, steve nospam wrote:
> On Jun 1, 8:10 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>
>
>> As Luuk said, you can do it in PHP. But in reality, how much are you
>> going to save? You'll have to copy/paste the PHP code instead of the
>> HTML, and your code (which is basically static).
>>
>> Maybe a better solution would be to use an editor which support macros.
>>
>
>
> Good idea! why do the php processing each time, if it can be done
> once.
> I thought about this after posting the question, that now the server
> has to do this string replacement each time the page is called, which
> is silly actually.
>
> What do recommend for this "macro" part? I use notepad now
> and it does not have many features. do you one which is HTML/php/
> javascript
> friendly? so many editors and will take long time to try them all.
>
Editors are a very personal decision. What works for me may or may not
work for you, and will definitely not work for some others.
And since this has nothing to do with PHP, you are much better off
asking in an appropriate newsgroup such as alt.html. The people there
can better recommend editors which will suit your needs for html coding.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|
Re: can one make a php function or macro with arguments to generate HTML code? [message #181781 is a reply to message #181771] |
Sat, 01 June 2013 14:22 |
bill
Messages: 310 Registered: October 2010
Karma: 0
|
Senior Member |
|
|
On 6/1/2013 6:21 AM, steve nospam wrote:
> I am newbie. I am writing HTML and find myself duplicating lots of
> code, which is the same except for 1 or 2 names/items in it.
>
> I do not know how to make a function or macro that takes arguments in
> HTML or CSS. Then I read that php is much more powerful and one should
> code HTML pages in php.
>
> Here is an example of what I have, I am just asking for a hint or a
> link on how to code this in php.
>
> <div class="blabla">
> <video poster="folder_name/image.png" controls>
> <source src="folder_name/movie.ogv" type="video/ogg">
> <source src="folder_name/movie.mp4" type="video/mp4">
> opps, browser does not support the video tag.
> </video>
> </div>
>
> The above block of HTML close is repeated many time. Each time, a
> different "folder_name" is used.
> So I end up copy/paste and edit this code many many times.
>
> It would be nice if I can define a function, and just pass it the
> folder_name and it returns back this whole code. So the above becomes
>
> <div class="name">
> make_video_code("ABC")
> </div>
>
> <div class="name">
> make_video_code("ADR")
> </div>
>
> <div class="name">
> make_video_code("ACB")
> </div>
>
> etc.... you get the idea.
>
> Is something like this possible? Does any one have a templates or
> example of how to do this in php? where to put the function
> make_video_code()?
>
> thanks
> Steve
>
In my case I use a program called NoteTab Pro for that. Not notePAD, but
NoteTAB; it's an excellent text editor and html generator with the
ability to, among many more things, hold templates and/or clickable
read-only files in one of its many clipbooks. Short learning curve,
inexpensive Pro version, and a pay-for Pro version is available.
Creating your own specialized clips is also easy; just highlight/copy
and then go to the clip pane and witch to the Clip pane and paste; the
highlighted part then becomes available at one double-click.
NO affiliation; just a long time user here.
You can check it out here:
NoteTab – A Prize-Winning Text Editor and HTML Editor
www.notetab.com/
NoteTab gets more done in less time. Try it! ... NoteTab Pro is another
of those utilities that once you have tried it, you won't go back. Jerry
Pournelle, BYTE ...
Download - NoteTab Light - Comparison Chart - This Prize-Winning HTML ...
|
|
|