WordPress.org

Ready to get started?Download WordPress

Forums

about the use of "echo" in template functions (7 posts)

  1. davidmarsal
    Member
    Posted 10 years ago #

    I don't understand the use of the "echo" function in the templates.
    Some functions return a variable, whereas others print it, and still others plan to allow both methods via a input parameter.
    I am writting some changes in the template-function*.php files in order to systematically use a returned variable, because I use those variables as parameters for the phplib's templates engine.
    My question is :
    Why do you use "echo" in template-functions*.php and not in the index.php ?
    Because, if there is an advantage, I would like to use it in my developments.
    Sure it's not always convenient to write echo blabla(); but in the other hand you can do what you want with the output of the function (store it, save it in file, send it to a html-template engine...)
    thanks a lot for your help.

  2. Matt Mullenweg
    Troublemaker
    Posted 10 years ago #

    Most (or all) of the template functions meant to be used in the template echo because they're meant to be as easy to use as possible, and that means making them less verbose.

  3. Jean-Pierre Michaud
    Member
    Posted 10 years ago #

    i would prefer myself to see a return instead of an echo... there is a lot of your functions that return the content instead of echoing it, so we have a control on when to display its content...

  4. Anonymous
    Unregistered
    Posted 9 years ago #

    I second that.

  5. zeroK
    Member
    Posted 9 years ago #

    Me too. Nothing against backward compatibility but IMO this change shouldn't really affect that much (only one = to add everytime you want to use a template function ;-) ) and it has immense benefits for people who want to integrate their blog into other apps or things like that :-)

  6. Anonymous
    Unregistered
    Posted 9 years ago #

    Looking at the two cases:
    1) you have functions returning and you want them to echo
    <?=myretfunc(); ?>
    2) you have functions echoingand you want them to return
    (all that stuff you posted above)
    I know which I would pick.
    How about the existing functions are left for compatibility, but that a new set is instigated. I've been using wordpress about an hour now and I've already been into the sourcecode to find get_bloginfo(); since I want to assign my blog title to a variable and call my own layout function that runs the rest of my site.
    so how about a get_*() version of every template function, that returns rather than echoes...

  7. sweavo
    Member
    Posted 9 years ago #

    reading the docs further, I see get_ is already taken by a bunch of echoing functions like get_links_list(). d'oh. I had assumed that the_ was used for that, like the_date(), the_time() etc.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.