adding my own php vars to smarty

skyrover

Joined: 2004-06-29
Posts: 13
Posted: Sun, 2006-08-13 21:29

I've been knocking around the docs for a couple of days now and I'm kind of stuck. What I would like to do is get a bunch of my own vars from a (non-g2) database and display them as part of a template.

Ultimately, this will probably go the route of a fully embedded integration, but I'm not able to do that yet.

The long version is that I run a small blog system, home-brewed (long story). The blog system has a set of about 20 templates for people to choose from. I was going to set up corresponding templates in G2, so if someone jumps from the blog to the album, the template essentially (visually) stays the same. My G2 is set up as a non-embedded install, with the blog users that have galleries each owning their own album. (actually, it's all in a G1 setup presently which is live, but I'm going to migrate it to G2 soon). So yes, you can see that ideally this is should be an embedded install, but in the meantime because I have bunch of users and photos in the system, I just wanted to run parallel templates and not be too concerned integrated admin and users and all that stuff.

So at a very basic level what I want to do is place a block of code in g2 - like a module - that will grab the owner of the album, hit the blog mysql db and find the corresponding owner of the blog (usually the same but not always), and return some info about their blog - the title of the blog, the URL (so i can build a 'back to blog' link), some nav bits, etc. Then I'd load the info coming from the blog DB as smarty vars so that I can drop them into the corresponding g2 themes. I want one block of my own php code feeding all the themes in g2.

I've gone through the module development tutorial, and have pretty much identified that is the place i need to be for doing this kind of thing. Where the tutorial leaves off is where i need to go, i.e. how do I reference the g2 variables (like the owner of the album the user is currently browsing) in order to pass that to my blog db function, and how do i take my vars and make them available to smarty?

tia, skyrover

 
skyrover

Joined: 2004-06-29
Posts: 13
Posted: Wed, 2006-08-16 01:08

gave up, got a Flikr api key...

 
Whiteside

Joined: 2006-08-26
Posts: 2
Posted: Sat, 2006-08-26 01:57

I can help you if you change your mind.

 
skyrover

Joined: 2004-06-29
Posts: 13
Posted: Sun, 2006-08-27 16:05

While I do in fact have a Flikr api key, I'm not really intending to go that route. My post was more of a plea for help.

I both want and need to stick with Gallery - it's a good tool for my needs, provided I can get it integrated properly. So to that end, your offer of additional assistance would be greatly appreciated.

 
Whiteside

Joined: 2006-08-26
Posts: 2
Posted: Mon, 2006-08-28 19:47

Okay, I'm not a Gallery dev, and I wanted to do the same thing a year ago, gave up like you, and started again about a month ago; so bear with me. I'm writing a tutorial right now to replace Kiril's... hopefully they post it when I'm done.

The short answer, to what I think your question is, is

$template->setVariable('myVarNameHere', 'theValueMyVarHas');

I'm assuming, probably wrongfully, that your module
-installs
-has a class in an inc file called something like "MyClassView"
-has a page that loads when you go to main.php?g2_view=myModule.MyClass

If you have the above things going, then add that $template line to your MyClassView in the inc file; then, in the tpl file, do this
{$myVarNameHere}
and loading main.php?g2_view=myModule.MyClass should give you
theValueMyVarHas

If you don't have the above things going or have more questions, that's cool, but we might have to talk in the irc channel or something.

Good luck.