Is it possible to display a special custom field (e.g. "price") for registered users only while for everybody else they would only see the "regular" custom fields (e.g. title, size, medium)? Any help would be greatly appreciated.
That gets me on the right track but since I'm such a newbie to this can you elaborate? As I say, I've added custom fields for every image on my site and I'd like to add one more that can only be viewed if a person is registered (and has the right permissions). So would I add code to the .tpl file that basically asks if a person is registered and then if so to display the custom field? Any chance you can give me an example of such code? Many thanks.
floridave
Joined: 2003-12-22
Posts: 25945
Posted: Thu, 2009-02-05 01:17
Hard to explain without just doing the code for you. anyway not test but should get you you going:
You do it with this line of code (only once at the top of the photo template):
I am finally getting back to this and after playing with it am still having problems implementing. So just to clarify: in your first line of code that goes at the top of my_theme's/templates/local/Photo.tpl? And then in your second and third code snippets those get added to /modules/customfield/templates/blocks/local/CustomField.tpl?
Since the CustomField.tpl already displays all of my {$fields} (e.g. Title, Medium, etc.), isn't there some way simply within the CustomField.tpl to tell it NOT to display "my_field" (i.e. Price) to use your example UNLESS the user is a "RegisteredUser"...?
floridave
Joined: 2003-12-22
Posts: 25945
Posted: Mon, 2009-03-09 01:53
Quote:
in your first line of code that goes at the top of my_theme's/templates/local/Photo.tpl?
Yes.
Quote:
And then in your second and third code snippets those get added to /modules/customfield/templates/blocks/local/CustomField.tpl?
no they get added to my_theme's/templates/local/Photo.tpl where you like the data to appear.
Quote:
NOT to display "my_field" (i.e. Price) to use your example UNLESS the user is a "RegisteredUser"...?
I guess, but that would be a whole different bit of code.
Thanks for your quick reply. So I just tried it exactly as you specify, deleted template cache, but it's still not working. Again, I am totally new to .php and Smarty tags (not to mention Gallery2 itself) so it's probably something I'm not doing. Any other advice you can give me? Something I'm not clear on is that the regular custom fields already get pulled into the photo display pages though it doesn't appear that the callback reference previously exists on the Photo.tpl page?! So the code you've suggested is new to the Photo.tpl page correct? And it would also supplement what does exist on the CustomField.tpl?
kvan2000
Joined: 2008-06-18
Posts: 8
Posted: Mon, 2009-03-09 04:08
Hold the phone, it was something I was doing.... Now to somehow integrate with the rest of my custom fields and I am there....
kvan2000
Joined: 2008-06-18
Posts: 8
Posted: Mon, 2009-03-09 05:24
Dave,
One last thing I'm hoping you can help me with and then I'm there. What is the proper syntax for accessing a specific custom field in the case that I do have spaces in the name of the custom field? For example, if I'm trying to display: {$block.customfield.LoadCustomFields.fields.my field} where "my field" actually has a space in it? Thanks for all your help.
kvan2000
Joined: 2008-06-18
Posts: 8
Posted: Tue, 2009-03-10 00:45
Dave,
Forget that last question. I went back and changed my fields so that they are one word only. I've also (almost) achieved what I set out to do, that is enable a registered user to see an extra custom field that is otherwise not available to non-registered users. Essentially (and I gathered this from comments you had previously posted to another similar request) I edited the CustomFields.tpl so that registered users can see the entire array (including the extra special custom field) and then I added a bunch of {if} {else} statements for those fields that everyone else can see. My final question is this: how do I get the album pages to display the same information that the photo pages display (i.e. are they pulling in different CustomFields.tpl's)? At the moment, I have checked the "Details" box via the admin web module for the extra custom field and that works fine. When I check the "Summary" box, however, for the same field that displays the extra custom field regardless of whether a user is registered or not--seemingly the same CustomFields.tpl does not apply to the albums page? Any help you can give me is greatly appreciated.
floridave
Joined: 2003-12-22
Posts: 25945
Posted: Tue, 2009-03-10 01:12
You can have different custom fields for album and photo pages.
I realize that and actually wan the same custom fields to appear both pages. For some reason I can't figure out though the album page displays the special custom field rgardless of whether the user is registered or not almost as if it is ignoring my CustomFields.tpl? Is that possible?
Posts: 25945
http://codex.gallery2.org/Gallery2:Themes:Reference:Variables#User_Information
it show you how to get users info and display different info.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 8
That gets me on the right track but since I'm such a newbie to this can you elaborate? As I say, I've added custom fields for every image on my site and I'd like to add one more that can only be viewed if a person is registered (and has the right permissions). So would I add code to the .tpl file that basically asks if a person is registered and then if so to display the custom field? Any chance you can give me an example of such code? Many thanks.
Posts: 25945
Hard to explain without just doing the code for you. anyway not test but should get you you going:
You do it with this line of code (only once at the top of the photo template):
{g->callback type="customfield.LoadCustomFields" itemId=$item.id|default:$theme.item.id}Then you can call any of the custom field by its name in the following way (assuming the name in the example is my_field):
{if !empty($block.customfield.LoadCustomFields.fields.my_field)} {$block.customfield.LoadCustomFields.fields.my_field} {/if}Then wrap that all up like:
{if $user.isRegisteredUser} {if !empty($block.customfield.LoadCustomFields.fields.my_field)} {$block.customfield.LoadCustomFields.fields.my_field} {/if} {else} Welcome, guest! {/if}Don't put spaces in your custom field name as that adds more code complexity.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 8
I am finally getting back to this and after playing with it am still having problems implementing. So just to clarify: in your first line of code that goes at the top of my_theme's/templates/local/Photo.tpl? And then in your second and third code snippets those get added to /modules/customfield/templates/blocks/local/CustomField.tpl?
Since the CustomField.tpl already displays all of my {$fields} (e.g. Title, Medium, etc.), isn't there some way simply within the CustomField.tpl to tell it NOT to display "my_field" (i.e. Price) to use your example UNLESS the user is a "RegisteredUser"...?
Posts: 25945
Yes.
no they get added to my_theme's/templates/local/Photo.tpl where you like the data to appear.
I guess, but that would be a whole different bit of code.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 8
Thanks for your quick reply. So I just tried it exactly as you specify, deleted template cache, but it's still not working. Again, I am totally new to .php and Smarty tags (not to mention Gallery2 itself) so it's probably something I'm not doing. Any other advice you can give me? Something I'm not clear on is that the regular custom fields already get pulled into the photo display pages though it doesn't appear that the callback reference previously exists on the Photo.tpl page?! So the code you've suggested is new to the Photo.tpl page correct? And it would also supplement what does exist on the CustomField.tpl?
Posts: 8
Hold the phone, it was something I was doing.... Now to somehow integrate with the rest of my custom fields and I am there....
Posts: 8
Dave,
One last thing I'm hoping you can help me with and then I'm there. What is the proper syntax for accessing a specific custom field in the case that I do have spaces in the name of the custom field? For example, if I'm trying to display: {$block.customfield.LoadCustomFields.fields.my field} where "my field" actually has a space in it? Thanks for all your help.
Posts: 8
Dave,
Forget that last question. I went back and changed my fields so that they are one word only. I've also (almost) achieved what I set out to do, that is enable a registered user to see an extra custom field that is otherwise not available to non-registered users. Essentially (and I gathered this from comments you had previously posted to another similar request) I edited the CustomFields.tpl so that registered users can see the entire array (including the extra special custom field) and then I added a bunch of {if} {else} statements for those fields that everyone else can see. My final question is this: how do I get the album pages to display the same information that the photo pages display (i.e. are they pulling in different CustomFields.tpl's)? At the moment, I have checked the "Details" box via the admin web module for the extra custom field and that works fine. When I check the "Summary" box, however, for the same field that displays the extra custom field regardless of whether a user is registered or not--seemingly the same CustomFields.tpl does not apply to the albums page? Any help you can give me is greatly appreciated.
Posts: 25945
You can have different custom fields for album and photo pages.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 8
I realize that and actually wan the same custom fields to appear both pages. For some reason I can't figure out though the album page displays the special custom field rgardless of whether the user is registered or not almost as if it is ignoring my CustomFields.tpl? Is that possible?