Support » Requests and Feedback » about the use of “echo” in template functions

  • 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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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.

    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…

    I second that.

    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 🙂

    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…

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘about the use of “echo” in template functions’ is closed to new replies.