Vanilla open source was terminated 1 January 2025 by Higher Logic. See this announcement for more information.

Vanilla variables used in Custom Page

evolucjaevolucja New
edited January 2012 in Vanilla 2.0 - 2.8

Can I use Vanilla variables in Custom Pages? For example I want to make pages avaiable only for some users or something like "Hello, $username" or "You've got a nice avatar: [AVATAR IMG], $username".

Best Answers

  • sahotataransahotataran ✭✭✭
    Answer ✓

    yes you can use all variables, Classes, Functions from vanilla in custom pages.

    There was an error rendering this rich post.

  • sahotataransahotataran ✭✭✭
    Answer ✓
    $Session = Gdn::Session();
    if ($Session->IsValid()) {
    $userid = $Session->UserID;
    $Name = $Session->User->Name; }

    above can be used to check if session is valid i.e user is logged in. then u can get his username and userid. then using userid u can check for function in UserModel to get the userdetails from ID or USERNAME. i suppose that you are familiar with programming and u can go through the code to find out what details u want - i have given u userid and username.

    i tried $this->AddModule('CategoriesModule'); but it doesnot seem to work on mine. u can try on your install if it works for u

    There was an error rendering this rich post.

Answers

  • sahotataransahotataran ✭✭✭
    Answer ✓

    yes you can use all variables, Classes, Functions from vanilla in custom pages.

    There was an error rendering this rich post.

  • Well.. so how can I use them? I made a Custom Page with

    var_dump(get_defined_vars());

    and I don't see there any user or other useful data..

  • i created a page demo.php in custom pages plugin and put

    <?php if (!defined('APPLICATION')) exit();
    $this->Head->Title('Demo title for using Custom Page Plugin!');
    $DiscussionModel = new DiscussionModel();
    $DiscussionData = $DiscussionModel->Get(0, 10);
    var_dump($DiscussionData );
     ?>

    which set the title of page as Set above and printed out the first 10 discussions.

    what kind of data you want to print? - you will have to look for variable in core and echo it out or var_dump();

    There was an error rendering this rich post.

  • is there any list of all variables I can view and set in Custom Pages? Especially I want to know if user is logged, his username and avatar image.

    Can I make queries in Custom Page? Can I set a default sidebar? Can I set content of own sidebar?
    If yes, can anyone tell me how? :)

  • sahotataransahotataran ✭✭✭
    Answer ✓
    $Session = Gdn::Session();
    if ($Session->IsValid()) {
    $userid = $Session->UserID;
    $Name = $Session->User->Name; }

    above can be used to check if session is valid i.e user is logged in. then u can get his username and userid. then using userid u can check for function in UserModel to get the userdetails from ID or USERNAME. i suppose that you are familiar with programming and u can go through the code to find out what details u want - i have given u userid and username.

    i tried $this->AddModule('CategoriesModule'); but it doesnot seem to work on mine. u can try on your install if it works for u

    There was an error rendering this rich post.

Sign In or Register to comment.