HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to decide what to show in {asset name="Panel"}

edited July 2016 in General Banter

Hello Forum,
I have a question.
With {asset name="Panel"} we get all the available assets for pannel. For example if I only want BoxFilter or BoxCategory content (two read blocks in screenshot), what I have to do?
Let make you clear with this screenshot:

If I only want any of these red blocks or any two, how can I do that.
I did some google and found this
https://vanillaforums.org/discussion/29934/side-bar-panel-categories-recent-discussion-activity
and
https://vanillaforums.org/discussion/comment/225254#Comment_225254
but still couldnt figured it out.
After google I also found that I can create my own arbitrary assets in my templates and simply add content to them using Gdn::controller()->addAsset('AssetName', $Content, 'ContentName') but dont know where to use Gdn::controller()->addAsset('AssetName', $Content, 'ContentName')
If you didnt understand my questions , please feel free to ask again.

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    The second link already holds all information you need. Simply do what is described there and see what happens.

    Your understanding of "Asset" might be wrong. In the default.master.tpl, there is only the layout. Where the panel, the navigation and the main content shall be, but not the content of those.

    In order to change the layout you need default.master.tpl, in order to change content you need e.g. a themehooks file

  • @R_J said:
    The second link already holds all information you need. Simply do what is described there and see what happens.

    Your understanding of "Asset" might be wrong. In the default.master.tpl, there is only the layout. Where the panel, the navigation and the main content shall be, but not the content of those.

    In order to change the layout you need default.master.tpl, in order to change content you need e.g. a themehooks file

    Well I did like you said here https://vanillaforums.org/discussion/comment/225254#Comment_225254

    // this will be called on every page
    public function base_render_before ($sender) {
    // don't show categories
    unset($sender->Assets['Panel']['CategoriesModule']);
    }

    And this code should remove the secound red block above right? or it just removes the first list item 'categorie' of this second red block ? In my case both didnt work.
    I have not so much idea so can you please explain or provide some link to explain what exactly 'Asset' and 'module' are ?
    I am using 2.2.1.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    what exactly 'Asset' and 'module' are ?

    a module is a widget , a block of some content like a clock or links..

    an asset contains modules/widgets

  • R_JR_J Ex-Fanboy Munich Admin

    In the standard layout there are four "assets" i.e. areas/containers/placeholders/whatever:
    1. Head - the header
    2. Foot - the footer
    3. Panel - sidebar
    4. Content - main content container

    -----------------------------------
    |   Head                                    |
    -----------------------------------
    | Panel | Content Content Content Content |
    | Panel | Content Content Content Content |
    | Panel | Content Content Content Content |
    | Panel | Content Content Content Content |
    | Panel | Content Content Content Content |
    | Panel | Content Content Content Content |
    -----------------------------------
    |   Foot                                    |
    -----------------------------------
    

    Modules are some small snippets like widgets. So if you would add a module to the "Foot" asset, it would be shown in the footer of the page. But normally modules are in the Panel.

    What you marked red above, are modules. If you want to "unset" it, so that it is not loaded, you must know the class name. Though not the css class name, but the name of the php object. Although it is not the css class name, it still is a great hint. Panel modules almost always are of the class Box and BoxModuleName.
    Looking at the above, you will find out that this module has the css class names "BoxFilter BoxDiscussionFilter".

    Now do a full text search for "DiscussionFilter" and you will see that there is a module with that name: "DiscussionFilterModule".

    Try this line in your code: unset($sender->Assets['Panel']['DiscussionFilterModule']);

  • @R_J said:

    Modules are some small snippets like widgets. So if you would add a module to the "Foot" asset, it would be shown in the footer of the page. But normally modules are in the Panel.

    What you marked red above, are modules. If you want to "unset" it, so that it is not loaded, you must know the class name. Though not the css class name, but the name of the php object. Although it is not the css class name, it still is a great hint. Panel modules almost always are of the class Box and BoxModuleName.
    Looking at the above, you will find out that this module has the css class names "BoxFilter BoxDiscussionFilter".

    Now do a full text search for "DiscussionFilter" and you will see that there is a module with that name: "DiscussionFilterModule".

    Try this line in your code: unset($sender->Assets['Panel']['DiscussionFilterModule']);

    Thanks Man. That really helped a lot.
    Now I know what are modules, assets.
    After{debug} you get all the assets, modules and so on.

    Try this line in your code: unset($sender->Assets['Panel']['DiscussionFilterModule']);

    I want something else.
    for example: in default.master.tpl, if I only want DiscussionFilterModule then I write {module name="DiscussionFilterModule"} and with{asset name="Panel"} we get all the modules and thats obvious.
    And my question is : can we get all the modules except any one.

    forexample: get all the modules with {asset name="Panel"} except {module name="DiscussionFilterModule"} this module.

    The reason behind why I need so is that ; I want_ {searchbox}_ and DiscussionFilterModule in one div. I know thats sounds strange but its my boss demand =)

  • R_JR_J Ex-Fanboy Munich Admin

    This is no Vanilla problem, since $sender->Asset['Panel'] is only an array.
    You can solve your task with vanilla php (excuse the pun): http://php.net/manual/en/function.array-intersect-key.php

    $sender->Assets['Panel'] = array_intersect_key(
        $sender->Assets['Panel'],
        ['DiscussionFilterModule' => null]
    );
    
  • @R_J said:
    This is no Vanilla problem, since $sender->Asset['Panel'] is only an array.
    You can solve your task with vanilla php (excuse the pun): http://php.net/manual/en/function.array-intersect-key.php

    $sender->Assets['Panel'] = array_intersect_key(
        $sender->Assets['Panel'],
        ['DiscussionFilterModule' => null]
    );
    

    Thanks for the answer.
    Do I have to write above code in class.themehooks.php?
    I did that but the probem is , whattever you write here, doesnt do anything.
    (because also this code
    unset($sender->Assets['Panel']['CategoriesModule']);
    unset($sender->Assets['Panel']['DiscussionFilterModule']);
    didnt work )

    Do I have to mention this file path somewhere?.
    I have this file on themes/mytheme/class.themehooks.php

    I would appreciate your help

  • Do I have to write above code in class.themehooks.php?
    I did that but the probem is , whattever you write here, doesnt do anything.
    (because also this code
    unset($sender->Assets['Panel']['CategoriesModule']);
    unset($sender->Assets['Panel']['DiscussionFilterModule']);
    didnt work )

    Well I found the solution of this problem.
    insteed of class.themehooks.php, i renamed it to class.mythemenamethemehooks.php and placed it to themes/mythemename/class.themehooks.php and it works.

    @R_J what you hae mentioned here https://vanillaforums.org/discussion/comment/225254#Comment_225254 is incorrect (or at least doesnt work for me).

    unset($sender->Assets['Panel']['DiscussionFilterModule']); will hide DiscussionFilterModule everywhere and with this code {module name="DiscussionFilterModule"} in default.master.tpl i get DiscussionFilterModule everywhere.
    I have a small question (my be you find dumm but consider that I am new in vanilla):
    How can I get, for example, DiscussionFilterModule, in those places/pages where with {asset name="Panel"} yo get.
    I mean, normally (without unset) you get DiscussionFilterModule with {asset name="Panel"} _but not everywhere (example on edit-profile, you dont get _DiscussionFilterModule ) in the same way I want DiscussionFilterModule with {module name="DiscussionFilterModule"} on same places/pages like with {asset name="Panel"}.
    I hope you understand my question.
    Hopping to get response.

  • Hello,
    I want to display something if $CssClass !='Dashboard'
    like
    {if $CssClass !='Dashboard'} {module name="DiscussionFilterModule"} {/if}
    but for $CssClass , it doesnt work.
    Can you suggest how can I proceed this.

  • R_JR_J Ex-Fanboy Munich Admin

    Okay, I guess you have to take a step back to understand more.

    Vanilla uses Smarty for the rough layout. All other things are done in php. Vanilla uses a MVC (Model View Controller) architecture. Based on the url (the Controller), some data is fetched from the database (the Model) and this data is passed to a file (the View) which is send back to your browser.

    What you are trying to change is, which controllers will attach the DiscussiobFilterModule. Best way to ask that question is the following

    I want to see DiscussionFilter in
    myforum.com/discussions
    myforum.com/discussion
    myforum.com/categories
    myforum.com/profile

    It is shown in the first three, but not in the last one.

    public function base_render_before($sender) {
        // Add the DiscussionFilter
        if ($sender->controllerName == 'profilecontroller') {
            $sender->addModule('DiscussionFilterModule');
        }
        // Delete every module but the DiscussionFilter.
        if (
            in_array(
                $sender->controllerName, [
                    'discussionscontroller',
                    'discussioncontroller',
                    'categoriesscontroller'
                    'activitycontroller'
                ]
            )
        ) {
            $sender->Assets['Panel'] = array_intersect_key(
                $sender->Assets['Panel'],
                ['DiscussionFilterModule' => null]
            );
        }
    
    }
    

    Generally, I would advise not to change the default.master.tpl in order to make changes like that. Only change it if you want to make layout changes. What is in an asset is a "content" change which should be changed with the themehooks file.

    There is a low learning curve for small changes in Vanilla. Get some knowledge in MVC and Vanillas file structure and you'll be making big changes with few lines of code soon!

Sign In or Register to comment.