ElkArte Community

Project Support => General ElkArte discussions => Topic started by: Antechinus on June 13, 2013, 08:02:55 pm

Title: Just curious about php syntax.
Post by: Antechinus on June 13, 2013, 08:02:55 pm
When I was looking through templates yesterday, I noticed this:



Code: [Select]
function template_build_poster_div($message, $ignoring)
{
    global $context, $settings, $options, $txt, $scripturl, $modSettings;

    $poster_div = '';

    // Show information about the poster of this message.
    $poster_div .= '
                        <ul class="dropmenu">
                            <li>';

    // Show a link to the member's profile.
    $poster_div .= '
                                <a href="' . $scripturl . '?action=profile;u=' . $message['member']['id'] . '">
                                    <span class="name">' . $message['member']['name'] . '</span>
                                </a>';

Obviously the $poster_div .=' is just substituting for the old echo' and is doing the same job, but echo' is still used in other places. What's the rationale regarding the new syntax? It's more verbose, and I can see it being possibly more confusing, but I assume there is a reason it was chosen.
Title: Re: Just curious about php syntax.
Post by: Spuds on June 13, 2013, 08:18:19 pm
I did that (and this was asked and answered before  O:-) ) ... That code is used in to places, so rather than duplicate 99% of the same code in two places I chose put in in a separate function and just call it to build the info and then echo it back.
Title: Re: Just curious about php syntax.
Post by: Antechinus on June 13, 2013, 08:24:27 pm
Ah. So is this to deal with both posts and PM's with less code overall?
Title: Re: Just curious about php syntax.
Post by: Spuds on June 13, 2013, 08:32:04 pm
It was a while ago that I did that, but I seem to recall it was for when the "no avatar" option which was changed to a compact view as a test/request ... not sure that is still even in the theme  O:-)

Anyway at one point that code was called either by the sidebar avatar view or by the dont show avatars (= no sidebar crud) view
Title: Re: Just curious about php syntax.
Post by: Antechinus on June 13, 2013, 09:13:28 pm
Yeah I like the no sidebar crud option as an option. I was going to tweak it so that the name went with the keyinfo h5 etc, and the post went full width under all that. I can see that being quite a popular option, especially for notebooks.