Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-04-21 06:43:37

Siguo
Member
From: Beijing, China
Registered: 2008-05-22
Posts: 44

need help: what's the advance using these html functions?

I’m writing some txp code these days, and there’s one problem really confused me.

the problem is: what’s the advance using these html functions?

like these: startTable(), fInputlable(), tr(), td()…

why we should use these functions instead of “raw html code” like <table><tr>…bla bla?

are there really some important differents I missed?

any way, use raw html is more efficient than call some functions.

thanks.

Last edited by Siguo (2010-04-21 06:48:30)

Offline

#2 2010-04-21 07:00:37

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: need help: what's the advance using these html functions?

Not that much, but there are differences/advantages; Amount of code is smaller, and when dealing with dynamic content, databases and whatnot, you have to validate the input, like check if it is there and if it’s not, fill the column with something else like a space to keep some browsers happy.

For example:

td($myVariable)

Versus:

'<td>' . (($myVariable) ? $myVariable : '&#160;'). '</td>'.

Which one would you choose? I don’t personally use TXP’s HTMLshortcutFunctions, but they are definetly good for upkeeping (for TXP’s core at least) and they do stuff that you don’t have to. That’s really the point for having libraries and stuff; that you don’t have to. Also it centralizes all HTML markup so you don’t have to look it everywhere. It’s not that you have to use them, not at all, but for TXP they are better than fine.

Last edited by Gocom (2010-04-21 07:05:34)

Offline

#3 2010-04-21 07:26:44

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,328
Website Mastodon

Re: need help: what's the advance using these html functions?

Not to be underestimated: By using PHP functions like td() you are quite protectected from omitting closing tags and other invalid HTML. Basically, you use PHP’s syntax validator as a HTML authoring guide.

Offline

#4 2010-04-21 07:26:59

Siguo
Member
From: Beijing, China
Registered: 2008-05-22
Posts: 44

Re: need help: what's the advance using these html functions?

“Amount of code is smaller, and when dealing with dynamic content, databases and whatnot, you have to validate the input, like check if it is there and if it’s not, fill the column with something else like a space to keep some browsers happy.”

Thanks Gocom, I think I’ve understood the differences/advantages, the point is these functions are better to deal with dynamic content.

and like Wet said, it ensure our outgoing HTML authorized.

When we need raw html, just use it.

Last edited by Siguo (2010-04-21 07:36:37)

Offline

Board footer

Powered by FluxBB