Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
Passing vars to .tpl
dizpers



Joined: 03 Oct 2011
Posts: 15

Posted: 10/07/11 08:54 
Hi all! I'm a new in jamroom module development and have some questions - could you help me please?Smile I don't understand - how I can pass variables from controller (which located in root directory) to my .tpl file (located in /themes/myTheme/myModule.tpl )?

I use now only one way to do it - create a new smarty function for my component and use it in .tpl file to display some info from database. But I think - it's not a good way to do so - we need to pass variables from controller...

PS
And could you explain me - does JamRoom based on MVC pattern or not? (I see controller and view... but don't see a model)

TIA!

Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 10/07/11 20:49 
you can structure any way you want. what part is MODEL? schema.php maybe Im not up with all the technical terms.

For me I use the main file in the root directory to establish zones that exist and put a switch at the bottom to redirect to sections.

I keep all of my sections in a file with another switch to functions related to the sections, and have a class for each section.

From the class the individual methods/functions (depending on what word you like) go and get all the data and pass that out to the templates like this:


Code
    public function view() {
        global $_post, $jamroom, $_user;
        $interesting_id = (int) ($_post['interesting_id'] > 0) ? $_post['interesting_id'] : 0;
        if($interesting_id == 0){
            jmLogger(0, 'CRI', 'apMymodule: view was opened without an interesting id.');
            print "error: there was no interesting id.";
            return;
        }
        //-----------------
        //interesting data
        //-----------------
        $sql = "SELECT *
                  FROM jamroom_Somewhere_interesting
                  WHERE interesting_id = {$interesting_id} ";

        $interesting_data           = dbQuery($sql, 'SINGLE');
        $data                       = array_change_key_case($interesting_data, CASE_UPPER);


        htmlShowTemplate('apMymodule, 'index.tpl', $data);  // the index.tpl file in this case will be located in /modules/apMymodule/templates/index.tpl  if you want to use the skin, then use 'skin' instead of the module name.
    }



_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
dizpers



Joined: 03 Oct 2011
Posts: 15

Posted: 10/07/11 21:11 
Big thx to you! And one another question - how I should use $data array in my .tpl file?



Last edited by dizpers on 10/07/11 23:38; edited 1 time in total
Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 10/07/11 22:08 
dont need to do anything to use it, it wont exist.

you changed the db keys to uppercase so they will be the vars in the template.

put in {debug} into the template to see all the vars available.

eg:
If you do this
$data['MY_NAME'] = 'waldo';
$data['FAVORITE_FOOD'] = 'chocolate';

Then in the .tpl files you can use
{$MY_NAME} to output waldo

so in .tpl
"Hello my name is {$MY_NAME} and my favorite food is {$FAVORITE_FOOD}"

build some cool modules and show us what you can do. Smile


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
dizpers



Joined: 03 Oct 2011
Posts: 15

Posted: 10/08/11 07:59 
I have some problems with adding new section to profile page (site.com/member/2 for example).

1. In file /themes/Nova/Menu.cfg I added a new section:


Code


[m_albums]
    page        = "jrAlbumsList.php"
    text_default = "Albums"
    onclick_add  = "jrHideComments();jrHideFanForm();"



So, and now I have a new link "Albums" in profile page

2. I added a new .tpl file in /themes/Nova :

/themes/Nova/jrAlbumsList.tpl

3. I updated my theme.cfg

/themes/Nova/theme.cfg

added:


Code
jrAlbumsList.tpl | jrAlbumsList.php


So, now I have a section in profile page, which named "Albums' and it's link is http://site.com/members/4/jrAlbumsList.php

but it isn't connected with my module cotriller (site.com/jrAlbumsList.php) how I can connect them? I mean - to provide logic in contoller and show data in profile tab.

Back to top
dizpers



Joined: 03 Oct 2011
Posts: 15

Posted: 10/08/11 08:54 
So, I solved my problem by adding in /themes/Nova/Menu.cfg:


Code
[m_albums]
    page        = "../../jrAlbumsList.php"
    text_default = "Albums"
    onclick_add  = "jrHideComments();jrHideFanForm();"


Back to top
Michael
Jamroom Team


Joined: 22 Apr 2008
Posts: 3423
Location: Tokyo

Posted: 10/08/11 16:44 
jrSomeFunction()

The "jr" part of that means the function was created by the Jamroom team. for your functions pick 2 letter prefix.

I use "ap" for my company apicos.com. so all my modules are
apGraphs
apAffiliate
apSomething
etc....

If you start naming functions you created as jr...... it will get confusing for others looking at your code because they wont be able to find documentation. so maybe "dzAlbumsList" or "diAlbumsList" or whatever you like.

other prefixes ive seen around are "n8" "pa" "qik" off the top of my head, im sure there are others.


_________________
Michael Ussher
Jamroom Network Team Member: http://www.jamroom.net
Priority Support: http://www.jamroom.net/Support_Center
Back to top
dizpers



Joined: 03 Oct 2011
Posts: 15

Posted: 10/09/11 11:39 
Thx, I'll bear in mind this rule:)

Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.