Display a New Module Template?

Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Let's say I want to create a new template running a list similar to the item_index.tpl within a module.

So just for shiggles we call it shiggles.tpl and make a button going to it.

<a href="{$jamroom_url}/{$profile_url}/{$murl}/shiggles.tpl" title="Big Trouble No Bubbles"><span class="sprite_icon sprite_icon_30"><span class="sprite_icon_30 sprite_icon_30_img sprite_icon_30_star2"> </span></span></a>

Why is it that the system will not display the template? It won't give me page not found , it will just take me to the profile index.

I've looked at this doc but there is no example of what I am trying to do so it's not very helpful (I'm not a programmer) - https://www.jamroom.net/the-jamroom-network/documentation/development/789/module-file-system-structure#-templates-

It seems like maybe the same question was asked here but I can't see the answer as applying to my situation.

https://www.jamroom.net/the-jamroom-network/forum/jamroom-developers/8741/module-url-question

The new template is simply to grab what's already available just as the current item_index.tpl, does by running an item_list. So why should an array and smarty functions need to be defined in the index.php or include.php as the docs seem to indicate?

I mean I don't see that done in the index.php for the item_index.tpl, so why would a similar template need all that? If it's necessary, where is it already implemented so I can copy?

Maybe it's Profile.Php I should be looking at, but I don't see anything related to that which would help me get the new template to display either.

Can someone simplify in laymans terms what needs to be done here and give me an example to follow?


--

Ken Rich
indiegospel.net

updated by @ken-rich: 08/30/16 03:20:08PM
brian
@brian
8 years ago
10,148 posts
You can't show a module template - you need to create it as a skin template. ALL the templates provided by modules are there as "defaults" for the skin so a skin designer does not have to create templates for each module.

so in your skin create:

whatever.tpl

and it will be available at:

yoursite.com/whatever

You can pass in variables as well - i.e.

yoursite.com/whatever/brian

The $_post.option variable would contain "brian" in the whatever.tpl file.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Hi Brian,

Thanks, I'll try that direction, though the docs seem like they need some editing as they seem to say some templates are reserved but you can name and use what you want outside of that.


--

Ken Rich
indiegospel.net
michael
@michael
8 years ago
7,717 posts
More specific please "some docs somewhere imply that some names are reserved" is hard to take action upon, so its unlikely anything will change.
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Hi Michael,

I gave a link to the docs above - https://www.jamroom.net/the-jamroom-network/documentation/development/789/module-file-system-structure#-templates-

Perhaps it would be helpful to elaborate on my thought process. I'm approaching the subject as someone not trained at programming. My goal is to simply have a page in a module to display a list with similar criteria as the one used in the item-index.tpl

1) I see this:

The reserved template file names are:
/templates/item_action.tpl
/templates/item_details.tpl
/templates/item_index.tpl
/templates/item_search.tpl
/templates/email_(something)_message.tpl
/templates/email_(something)_subject.tpl
Any other file names or directory names that you need can be chosen by you.
=============================
That leads me to believe I can create another template and name it whatever I wish as long as it's not a reserved name.

2) I also see this:

/Templates/
The /templates/ directory is the location to store any .tpl files that your module uses.

During a function in your module you can call the templates with the jrCore_parse_template() function.

Example of jrCore_parse_template():
note $_data is an array of values you want to pass into the template
jrCore_parse_template('template_name.tpl',$_data,'xxYourModule');

===========================================================

To me, that looks like a special coding function which will allow my new template to show. So I experiment with implementing it, ending in frustration.

3) Then I go the extra mile and search JR again coming up with this info from Paul.

https://www.jamroom.net/the-jamroom-network/forum/jamroom-developers/8741/module-url-question

============================================
It looks like b360 was asking the same question I have and Paul seems to be saying there is something one must do in the PHP to make the template show. His info is not detailed and the thread is closed, so I end up running more frustrating experiments in the PHP still just trying to get a simple page to display.

4) At this point, I'm convinced there is something I must do in the PHP but I don't understand what it is and where to implement. So I waste even more time looking through PHP codes in the index.php, include.php, and profile.php of various modules to see if I can find an example of the code that makes a template display. This also ends in frustration.

5) So I write in the forum and ask for help because I am clearly lost and what seems like it should be a very simple task (getting a simple page to display) has wasted many manhours.

So in the end, what I am looking to do is put a button in my module that will show on the item_index in every profile. It needs to open a page that will display a simple list from the module's datastore specific to the profile where the button is clicked.

If I am understanding correctly (what Brian has said) then I've been "barking up the wrong tree" the whole time. In other words, I have to put the template in the skin and devise a code that will list the module's items (specific to the profile where the button is clicked) there.

I'm not sure how to implement that so I'll have to experiment again. If my template was going to be in the module then it would have been {$jamroom_url}/{$profile_url}/{$murl}/NEWTEMPLATE.tpl

Now apparently it must be {$jamroom_url}/NEWTEMPLATE.tpl and obviously will not show inside the profile, like other profile pages do. It is also not going to have a profile specific URL. Yet somehow it must display profile specific info from the profile calling it, which seems counter-intuitive at the outset.

So at this point, I'm wondering how that will code and am looking at more time running experiments.


--

Ken Rich
indiegospel.net
brian
@brian
8 years ago
10,148 posts
Ken Rich:
That leads me to believe I can create another template and name it whatever I wish as long as it's not a reserved name.
That is not correct.

Quote:
To me, that looks like a special coding function which will allow my new template to show. So I experiment with implementing it, ending in frustration.
Yep - unless you want to learn module development, creating custom templates for modules is NOT what you want to do.

Quote:
5) So I write in the forum and ask for help because I am clearly lost and what seems like it should be a very simple task (getting a simple page to display) has wasted many manhours.
I'm not sure why you would waste hours when I had already posted that you were going about this the wrong way. You already pointed you are NOT a developer, so you want to avoid doing things that require you to be a developer.

Quote:
So in the end, what I am looking to do is put a button in my module that will show on the item_index in every profile. It needs to open a page that will display a simple list from the module's datastore specific to the profile where the button is clicked.
Then modify the skins/Active_Skin/profile_item_index.tpl. EVERY module's "item_index.tpl" file is rendered FIRST, then the contents are displayed using that template.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Hi Brian,

Quote: Brian: That is not correct.
If it's not correct, then perhaps it should be written in the docs a little differently, so that novices like myself won't make that assumption.

Quote: Brian: Yep - unless you want to learn module development, creating custom templates for modules is NOT what you want to do.
This leads me to believe my first assumption wasn't wrong but that there is indeed an advanced technique which would make a new (custom) template work in a module. So at this point, I rather suspect there are two paths, one too advanced for me, and another you are attempting to make me understand.

Quote: Brian: I'm not sure why you would waste hours when I had already posted that you were going about this the wrong way. You already pointed you are NOT a developer, so you want to avoid doing things that require you to be a developer.

It's not your fault. You didn't enlighten me until after I had ALREADY wasted many manhours and THEN asked for help in the forum (after the fact). I hate bothering you guys, I know you are busy, so I try to go by the docs and trial and error if I can. Usually, I can muddle through (not this time).

Now if the docs had said something like "this is an advanced technique, if you want a simple way to show a profile and module specific page you don't need a new module template read this LINK___________." Or if my searches would have turned up the easier way you are suggesting, I wouldn't have gone down this "rabbit trail".

That's why I am suggesting that maybe the easy way needs to be clarified in the docs, perhaps with an example for novices, since I rather expect I'll be hours more tinkering with codes trying to make this work. At least I am on the right "rabbit trail" now - lol.


--

Ken Rich
indiegospel.net

updated by @ken-rich: 05/25/16 03:03:56PM
michael
@michael
8 years ago
7,717 posts
Learning new stuff can be frustrating, good on you for trying. Please understand that its not our intention to try to teach everyone to become a developer, there are many courses and books available to do that.

Personally I LOVE books by the O'Reilly publishing company (except for the "Head First" series, hate those....). They write with very little fluff and just get what you need to know into your head.

eg:
Book: "Learning PHP"
http://www.amazon.com/Learning-PHP-Introduction-Popular-Language/dp/1491933577

Yes there are docs that are aimed at developers that may be confusing for non-developers.

TIP: One thing developers know instinctively to do is to go look at the code that is running to see what is happening, because the docs can only ever be an explanation of what the code is doing.

If it feels like time wasted, it might be better to hire someone to do it, no sense learning a language you don't want to use.
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Thanks Michael,

Since what I need often doesn't exist there are some things I need to create. I live on a TINY disability pension but even if it's something small and within my budget, I usually can't find a developer. So I am learning as best I can.

In this latest situation, I have created a page with sitebuilder and the list function. I now have everyone's items from my module listing properly. I have no problem creating a button from the item_index of my module to open that page.

The only thing I can't figure out is how to make it list ONLY the items from my module of the user who is viewing it, not all items from everyone.

So I figure it has something to do with $user or $profile_id but I can't make it work.

That's the only trick I need to solve my current dilemma.


--

Ken Rich
indiegospel.net
michael
@michael
8 years ago
7,717 posts
I have a copy of "Learning Php 5" that you can have for the cost of postage if you would like it.

Docs: "{jrCore_list}"
https://www.jamroom.net/the-jamroom-network/documentation/development/89/jrcore-list

Docs: "{debug}"
https://www.jamroom.net/the-jamroom-network/documentation/development/1477/debug
Quote:
$_conf = configured variables in the system
$_user = user looking at the screen
$_profile = the profile info of the profile being viewed
$_post = stuff coming in from outside the page
$_items = all the stuff asked for via jrCore_list
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Hi Michael,

Thanks - that would be awesome. If you give me your PayPal address I can reimburse shipping.

(addressed removed)

=========================================

I have learned to use debug on a regular basis and am somewhat familiar with the jrCore list commands (but not adept).

I have created a page using the sitebuilder's list function that ALMOST does what I need:

It lists my module's items exactly the way I want EXCEPT that it is displaying items from ALL item creators. I need it to list ONLY the items of the user who is viewing it. So I am looking for a search parameter to accomplish that. This is what I have so far:

TEMPLATE CODE:
{jrCore_list module="xxSales" search1="_item_id > 0" order_by="_created desc" pagebreak="10" pager="true" page=$_post.p }

CUSTOM TEMPLATE:
{jrCore_module_url module="xxSales" assign="murl"}
{if isset($_items)}
    {foreach from=$_items item="item"}
    <div class="item">
        <div class="container">
            <div class="row">
                <div class="col4">
                    <div class="block_image">
                        <a href="{$jamroom_url}/{$item.profile_url}/{$murl}/{$item._item_id}/{$item.sales_title_url}">{jrCore_module_function function="jrImage_display" module="xxSales" type="sales_image" item_id=$item._item_id size="512" class="img_scale"  alt=$item.sales_title width=false height=false} </a>                </div>
                </div>
                <div class="col8">
                    <div class="p10" style="overflow-wrap:break-word;vertical-align:top">
                        <h2><a href="{$jamroom_url}/{$item.profile_url}/{$murl}/{$item._item_id}/{$item.sales_title_url}">{$item.sales_title}</a></h2><br> 
                        <div style="font-size:16px;"><br>{$item.sales_text|truncate:270}<br><br></div>                       
                    </div>
                </div>              
                </div>
                </div>
                </div>               
                {/foreach}
{/if}



--

Ken Rich
indiegospel.net
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
brian: You can pass in variables as well - i.e. yoursite.com/whatever/brian
The $_post.option variable would contain "brian" in the whatever.tpl file

It probably seems so elementary to you as to not need elaboration but nevertheless, I am not following - dooh! The reason is when I look in the debug I don't see anything under $_post relating to profile names or users. So I can't see how that could possibly provide the solution.

Are you saying this code {$jamroom_url}/WHATEVER/{$_post.option} will cause the WHATEVER template to display ONLY the items of the user visiting it?

brian: Then modify the skins/Active_Skin/profile_item_index.tpl. EVERY module's "item_index.tpl" file is rendered FIRST, then the contents are displayed using that template.

I went to that template and the only thing there is
{$profile_item_list_content}

A couple things come to mind:

1) If EVERY module is using this won't my mod affect EVERY module. Unless you are suggesting I implement some type of IF/ELSE statement that targets my module alone.

Perhaps something like:

 {if $_params.module == "xxSales"}
   {jrCore_module_url module="xxSales" assign="murl"}
{if isset($_items)}

    {foreach from=$_items item="item"}

    <div class="item">

        <div class="container">
            <div class="row">
                <div class="col4">
                    <div class="block_image">
                        <a href="{$jamroom_url}/{$item.profile_url}/{$murl}/{$item._item_id}/{$item.sales_title_url}">{jrCore_module_function function="jrImage_display" module="xxSales" type="sales_image" item_id=$item._item_id size="512" class="img_scale"  alt=$item.sales_title width=false height=false} </a>
                    </div>
                </div>
                <div class="col8">
                    <div class="p10" style="overflow-wrap:break-word;vertical-align:top">
                        <h2><a href="{$jamroom_url}/{$item.profile_url}/{$murl}/{$item._item_id}/{$item.sales_title_url}">{$item.sales_title}</a></h2><br>
 
                        <div style="font-size:16px;"><br>{$item.sales_text|truncate:270}<br><br></div>
                       
                    </div>
                </div>

                
                    
                       </div>
                </div>
                </div>
                
                
    {/foreach}
{/if}
{/if}            

Is that the sort of thing you are suggesting?


--

Ken Rich
indiegospel.net

updated by @ken-rich: 05/26/16 09:50:52AM
douglas
@douglas
8 years ago
2,791 posts
What Brian is saying here:

brian: You can pass in variables as well - i.e. yoursite.com/whatever/brian
The $_post.option variable would contain "brian" in the whatever.tpl file

is if you have a template in your skin directory named whatever.tpl and you type yoursite.com/whatever/brian into your browser, then the variable {$_post.option} will be set to brian and only available in the whatever.tpl template.

Also, there is no need to check the $_params.module since the jrCore_list is telling the template what module your using. You might want to read over the jrCore_list function docs... https://www.jamroom.net/the-jamroom-network/documentation/development/89/jrcore-list if you haven't already.

Hope this helps!


--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos
michael
@michael
8 years ago
7,717 posts
{jrCore_list module="xxSales" search1="_item_id > 0" order_by="_created desc" pagebreak="10" pager="true" page=$_post.p }

to:
{jrCore_list module="xxSales" search1="_item_id > 0" search2="_profile_id = 1" order_by="_created desc" pagebreak="10" pager="true" page=$_post.p }

Will give you only those from profile_id 1.

to make it dynamic, use a variable in there:

{jrCore_list module="xxSales" search1="_item_id > 0" search2="_profile_id = $some_variable" order_by="_created desc" pagebreak="10" pager="true" page=$_post.p }


Which variable you use in the $some_variable position depends on which variables are available, for that see the {debug} info I posted.


Docs: "{debug}"
https://www.jamroom.net/the-jamroom-network/documentation/development/1477/debug
Quote:
$_conf = configured variables in the system
$_user = user looking at the screen
$_profile = the profile info of the profile being viewed
$_post = stuff coming in from outside the page
$_items = all the stuff asked for via jrCore_list
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
I am still trying to make my list work right. I have no problem to make it list ALL sales campaigns (items) - http://indiegospel.net/campaigns

However, after studying jrList and the tips I've received from staff, I still can't find a way to make it list ONLY the items created by the profile owner who is viewing it. So if I am logged in and go there, I should see ONLY the two I created in my profile, not everyone else's along with my own.

Inside the module, as the item_index.tpl it would do that but as a skin page it behaves differently. I don't understand why, or how to achieve that same functionality.

I know the list can be narrowed with an additional search parameter, but none of the ones I have tried have had the desired outcome.

So I am stuck here:

{jrCore_list module="xxSales" template="campaign_list.tpl" search1="_item_id > 0" search2="_______" order_by="_created desc" pagebreak="10" pager="true" page=$_post.p }



--

Ken Rich
indiegospel.net
michael
@michael
8 years ago
7,717 posts
what does:
{jrCore_list module="xxSales" search1="_item_id > 0" search2="_profile_id = 1" order_by="_created desc" pagebreak="10" pager="true" page=$_post.p }
show.

Should show only those from profile #1
douglas
@douglas
8 years ago
2,791 posts
And adding this parameter

profile_id=$_profile_id

instead of the search parameter should show only that profiles "campaigns" as long as the jrCore_list function is on a profile page, I'm not sure that works on a non-profile page.


--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Hi Michael,

Yes, if I plug in individual profile id's then it works correctly in that it only shows the items belonging to that id.

So the trick is, how do I tell it the profile id of the visitor?


--

Ken Rich
indiegospel.net
michael
@michael
8 years ago
7,717 posts
Read this:

Docs: "{debug}"
https://www.jamroom.net/the-jamroom-network/documentation/development/1477/debug
Quote:
$_conf = configured variables in the system
$_user = user looking at the screen
$_profile = the profile info of the profile being viewed
$_post = stuff coming in from outside the page
$_items = all the stuff asked for via jrCore_list

Then read the {debug} page.

anything in the $_user array is information from the user looking at the screen
anything in the $_profile array is information from the profile being viewed
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
Hi Douglas,

That just gives me a blank but I was thinjing the same thing. I can see with the debug that under $_user there is both profile_id and _profile_id.

So I would expect that either could be used as in:

{jrCore_list module="xxSales" search1="_item_id > 0" search2="profile_id = $_user.profile_id" order_by="_created desc" pagebreak="10" pager="true" page=$_post.p }

However, that and every permutation of it (syntax variations) I've tried just gives me a blank.


--

Ken Rich
indiegospel.net

updated by @ken-rich: 05/30/16 04:33:59AM
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
After dozens and dozens of attempts, I finally stumbled upon a solution. I remembered seeing Michael in a video typing (in regular text) something like value = x where x was something from an array.

So I typed in profile ID = {$_user.profile_id} and sure enough the profile ID showed. So I couldn't understand why it wouldn't work in the search.

Then it struck me - try putting the { } around it and see what happens. Sure enough it worked so my suspicion was correct, it was a syntax problem I was stumbling over.

Perhaps because I'm a novice I don't know the rules on when { } is necessary. Is there a link to those rules?

The working code is this:

 {jrCore_list module="xxSales" template="campaign_list.tpl" search1="_item_id > 0" search2="profile_id = {$_user.profile_id}" order_by="_created desc" pagebreak="10" pager="true" page=$_post.p } 



--

Ken Rich
indiegospel.net

updated by @ken-rich: 05/31/16 07:52:15PM
michael
@michael
8 years ago
7,717 posts
Ken Rich:.....Is there a link to those rules?.....

http://www.smarty.net/

And to do the docs searching for you on this occasion, this is the docs page regarding embedding multi-part variables in double quotes:

"Embedding Vars in Double Quotes"
http://www.smarty.net/docs/en/language.syntax.quotes.tpl

Another location that is very helpful to developers is:
http://stackoverflow.com

The search term "smarty3" will bring up many question/answer pairs.
douglas
@douglas
8 years ago
2,791 posts
Yeah, you shouldn't have to make it a search parameter... this should work.

{jrCore_list module="xxSales" template="campaign_list.tpl" order_by="_created desc"profile_id=$_profile_id  pagebreak="10" pager="true" page=$_post.p }

Or this:

{jrCore_list module="xxSales" template="campaign_list.tpl" order_by="_created desc" search1="profile_id = `$_profile_id`" pagebreak="10" pager="true" page=$_post.p }

Also, I'm not 100% sure why you would need the search1="_item_id > 0" in the jrCore_list either.


--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos

updated by @douglas: 05/31/16 06:04:56AM
Ken Rich
Ken Rich
@ken-rich
8 years ago
926 posts
douglas:
Yeah, you shouldn't have to make it a search parameter... this should work.
{jrCore_list module="xxSales" template="campaign_list.tpl" order_by="_created desc"profile_id=$_profile_id  pagebreak="10" pager="true" page=$_post.p }

Hi Douglas,
This first one gave me a syntax error which turned out to be the lack of a space between desc" and profile. After I added the space the syntax error disappeared but it showed ALL items not just mine.

Then I added user. to it and it worked. So the working code is:

{jrCore_list module="xxSales" template="campaign_list.tpl" order_by="_created desc" profile_id=$_user.profile_id  pagebreak="10" pager="true" page=$_post.p }


douglas:
Or this:
{jrCore_list module="xxSales" template="campaign_list.tpl" order_by="_created desc" search1="profile_id = `$_profile_id`" pagebreak="10" pager="true" page=$_post.p }
Also, I'm not 100% sure why you would need the search1="_item_id > 0" in the jrCore_list either.

The second code gave me a blank. So I added .user to it and the working code is:

{jrCore_list module="xxSales" template="campaign_list.tpl" order_by="_created desc" search1="profile_id = `$_user.profile_id`" pagebreak="10" pager="true" page=$_post.p }

Aside from that you are absolutely correct. Two search parameters were not necessary, in fact it can be done without any like your first example.

Oddly enough, both your versions did not require the { } brackets but if I remove them from my version it just gives a blank. Go figure - lol.


--

Ken Rich
indiegospel.net

updated by @ken-rich: 05/31/16 08:10:35PM
douglas
@douglas
8 years ago
2,791 posts
Is your jrCore_list function on a profile page? Is it in a template that starts with profile_?


--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos
SteveX
SteveX
@ultrajam
8 years ago
2,584 posts
If you are still looking at $_post there is this:
https://www.jamroom.net/ultrajam/documentation/code/1683/reading-the-post

$_user.profile_id will be the id of the user looking at the page, it will show the user's items from all profiles. If $_post is available and its a profile template, use $_post._profile_id to show things from that profile


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)