News:

Wondering if this will always be free?  See why free is better.

Main Menu

How to call board in display template?

Started by Mick., August 01, 2018, 08:05:43 AM

Previous topic - Next topic

Mick.

So im changing a few things in my display template when you read a post...

This is what i want.... Call out board name next to User

Mick In Tutorials <------- board name
July 25th 2018

So far i have ', $message['member']['link'], ' and ', $message['time'], ' working fine but i'm having a hard time calling the board where the post was made. I thought it would be some of these...


  • ', $context['current_board'], '
  • <a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>
  • ', $board['last_post']['link'], '

...but i can't figure out the combination.  Do i have to use if empty?  I attached an image :)

Dhayzon

Board name isn't  available on display, use =>  $context['jump_to']['board_name']

Mick.

Quote from: Dhayzon on August 01, 2018, 01:52:16 PM
Board name isn't  available on display, use =>  $context['jump_to']['board_name']
Awesome...i see the board name but it's not linked. It's just text.

Kindred

    [current_topic] => 62
    [current_board] => 17

are defined in $context, once you are into the message definition...
they are apparently not defined at the top of the page prior to loading messages.

I dropped some debug code just before
      // Show the message anchor and a "new" anchor if this message is new.


      echo '<div style="position:float;">';
        echo '<h2>$CONTEXT</h2>';
        echo '<pre>'; print_r($context); echo '</pre>';
        echo '<hr>';
        echo '<h2>Message</h2>';
        echo '<pre>'; print_r($message); echo '</pre>';
      echo '</div>';
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Kindred

also... it seems to be deifned in the linktree right at the start of the tmeplate

Code (within $context array) Select

    [linktree] => Array
        (
            [0] => Array
                (
                    [url] => https://test/index.php
                    [name] => Turtle Shell Productions Testing
                )

            [1] => Array
                (
                    [url] => https://test/index.php#c1
                    [name] => General Category
                )

            [2] => Array
                (
                    [url] => https://test/index.php?board=17.0
                    [name] => New Members
                )

            [3] => Array
                (
                    [url] => https://test/index.php?topic=62.0
                    [name] => Testing
                    [extra_before] =>
                )

        )
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

Eh, skip the messing about, global $board_info and get all the good stuff.

Mick.

https://www.idesignsmf.com/index.php/topic,541.0.html   <---It has the poster name in: whatever board that needs linked.

I was thinking something like:  $context['jump_to']['board_name']['link'] or  $context['jump_to']['board_name']['href'] or ', $post['board']['link'], ' but didnt work. i'll try that Arantor.

@Kindred Are suggesting the post anchor? That's not what i was looking, im looking for a direct link to the board and not the post. Perhaps i misunderstood your post.

Kindred

#7
you did...


although Arantor's comment is a better option.

The stuff I gave *IS* the board info...  it's also the topic info...

In the cases I show, the board name is "New Members" and is board #17


so, it's the third item in the linktree (name and link)
or you can construct the link from the $context['current_board']







but, as Arantor says...  gloablize $board_info and you have [id] and [name]


$board_info
(
    [id] => 17
    [moderators] => Array
        (
        )

    [cat] => Array
        (
            [id] => 1
            [name] => General Category
        )

    [name] => New Members
    [description] => If you have ZERO posts, this (and Announcements) should be the only board which you see...   Post here to see the rest of the site
    [num_topics] => 1
    [unapproved_topics] => 0
    [unapproved_posts] => 0
    [unapproved_user_topics] => 0
    [parent_boards] => Array
        (
        )

    [parent] => 0
    [child_level] => 0
    [theme] => 0
    [override_theme] =>
    [profile] => 1
    [redirect] =>
    [posts_count] => 1
    [cur_topic_approved] => 1
    [cur_topic_starter] => 15
    [groups] => Array
        (
            [0] => 0
            [1] => 2
            [2] => 9
            [3] => 12
            [4] => 11
            [5] => 10
            [6] => 4
            [7] => 13
            [8] => 5
            [9] => 6
            [10] => 7
            [11] => 8
        )

)
[edit] fixed code tags -Illori
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mick.

Here's the structure im working with...
                echo'

    <div class="avatar-box">
        <div class="avatar-frame">', $message['member']['avatar']['image'], '</div>


                                        <div class="avatar-frame-author">', $message['member']['link'], '';
                        if ($message['id'] == $context['topic_first_message'])
                 {
               echo'
                        ', $txt['in'], ' ' , $context['jump_to']['board_name'], '';
                 }

               echo'
                                    <br />
                                       <div style="font-size: 11px;">', $message['time'], '</div>
                                       </div>
                                    </div>';



This bit adds the board name, cool but is not a hot link.
' , $context['jump_to']['board_name'], '

The board name has to appear once in the first post so other users when they reply, it doesnt show on their post.
Didnt think it was going to be complicated lol

Illori

did you try adding $board to global and seeing what you can work with from there?

Arantor

Don't use $board, it only contains the board id (or is supposed to only contain the board id). $board_info is where it's at.

Mick.

Quote from: Arantor on August 01, 2018, 02:59:26 PM
Don't use $board, it only contains the board id (or is supposed to only contain the board id). $board_info is where it's at.
I used $board and it gave me the board number, id.

Kindred

Arantor... look at the array in my last post.   $board_info doesn't appear to include the URL.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mick.

Alright, let me come clean, im not sure where to place $board_info  :P

Illori

from the board name and id you can build the URL using $scripturl [i believe it is called]

Arantor

Quote from: Kindred on August 01, 2018, 03:01:35 PM
Arantor... look at the array in my last post.   $board_info doesn't appear to include the URL.

Why would you need the URL when it's guaranteed to be makeable from $scripturl . '?board=' . $board_info['id'] . '.0' ?

Kindred

lol...  well, yeah. I was just thinking there would be a premade one to cheat. :)

But, then again....   
$scripturl . '?board=' . $context['current_board'] . '.0' ?

should also work.... right?



Mick --
place it in the global list right at the top of the file...   where $context is also identified as a global
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

It would but if you're already pulling in $board_info to get the board name, you might as well get the board id from it ;)

Mick.

Like this?
global $context, $settings, $options, $txt, $scripturl, $modSettings, $board_info;

and use it like this?
', $scripturl . '?board=' . $context['current_board'] . '.0' ?, '

Dhayzon

#19
it's simply

<a href="', $scripturl, '?board=', $context['current_board'], '">', $context['jump_to']['board_name'], '</a>


only first message

if ($message['id'] ==  $context['topic_first_message'])
echo'<a href="', $scripturl, '?board=', $context['current_board'], '.0">', $context['jump_to']['board_name'], '</a>';


isn't necesary extra load data

Mick.

Quote from: Dhayzon on August 01, 2018, 03:35:07 PM
it's simply


<a href="', $scripturl, '?board=', $context['current_board'], '">', $context['jump_to']['board_name'], '</a>

Thank you! that worked!  Geez, i did it in my front page with Simple portal using just this ', $article['board']['link'], '  i figure it would be almost the same with SMF lol i was wrong.  Thank you much guys!


https://www.idesignsmf.com/index.php/topic,536.0.html

Mick.

Never thought of using $global_info either. learned something new :)

Kindred

I wouldn't use the jump_to...


(and yes, that is the correct way to globalize)
I'd do this....

<a href="', $scripturl, '?board='. $board_info['id'] . '">'. $board_info['name'] . '</a>
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Mick.

Quote from: Kindred on August 01, 2018, 03:43:17 PM
I wouldn't use the jump_to...


(and yes, that is the correct way to globalize)
I'd do this....

<a href="', $scripturl, '?board='. $board_info['id'] . '">'. $board_info['name'] . '</a>

Done.  Thank you!!

Advertisement: