If this is your first visit, check our documentation. To post, register or login.
Forums / Templates, Stylesheets, Page Layout / Embed php template within another php template based on drop-down menu selection?

Embed php template within another php template based on drop-down menu selection?

Started by mcqueeneycoins on 12 Jan 2012, 11:50 PM · Views: 2,398

Results 1 to 13 of 13
12 Jan 2012, 11:50 PM
#1
mcqueeneycoins avatar

mcqueeneycoins

Zen Follower

Join Date:
Jan 2008
Posts:
156
Plugin Contributions:
0

Embed php template within another php template based on drop-down menu selection?

Hi everyone,

I'm having some trouble accomplishing what I thought would be a relatively simple task.

I have a section of the site that will have several articles/posts. I'd like to create one page for the articles rather than 10-20 separate pages, with separate defines, templates, etc. To do this, I would have to embed the article within this one page, and it would have to automatically update based on a dropdown menu selection made by the user.

I was thinking this could be done with php--I can create a separate php file for each article (with the article text) and store it in one folder on the server (just like how zen cart pulls the header and footer information, etc.).

I know how to create a dropdown and how to embed php, but to make them work together is a struggle, let alone to make the page update automatically.

Can anyone help, please?

13 Jan 2012, 1:10 AM
#2
rstevenson avatar

rstevenson

Totally Zenned

Join Date:
Nov 2006
Location:
Dartmouth, NS Canada
Posts:
2,400
Plugin Contributions:
0

Re: Embed php template within another php template based on drop-down menu selection?

Why not use ZC's built-in EZpages and the EZpage menu? No need to reinvent the wheel.

And you might want to use the Ezpages Improved Menus mod, from Free Software Add Ons (link top-left on any forum page.)

Rob

Breakfast: the most important donut of the day.

13 Jan 2012, 11:10 AM
#3
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: Embed php template within another php template based on drop-down menu selection?

An ez-page "chapter", with one portal page linked in a nav menu and 10-20 other pages accessible through the chapter's table of contents, should serve to organize your articles.

14 Jan 2012, 5:46 PM
#4
mcqueeneycoins avatar

mcqueeneycoins

Zen Follower

Join Date:
Jan 2008
Posts:
156
Plugin Contributions:
0

Re: Embed php template within another php template based on drop-down menu selection?

Thanks for the suggestions, but I'm not quite sure that will work. Granted I'm not very familiar with the EZPage function, but I'd really like to make it as seamless as possible by keeping it to one page.
I want to have all the articles stored at https://www.mysite.com/articles with each file name being like article001.php, article002.php, etc. For example:

https://www.mysite.com/index.php?main_page=articles

Articles

Random text here to outline the purposes, etc.

Drop down menu with list of all articles (article 1, article 2, etc.)

Article content changes based on drop down menu

Back button

I found a way to make it work with iframes, but I wasn't able to auto-adjust the height of the iframe to conform with the article, so I had to veto that idea, unless anyone else has some suggestions.

Any other ideas?

14 Jan 2012, 6:01 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: Embed php template within another php template based on drop-down menu selection?

Is there a particular reason you need the article pages to be PHP instead of HTML, or is that just what you think you have to do?
Is it important that the same "random outline text" stay at the top of the page?
Is it important that the page as a whole not refresh when you select a new article? Why? If this is the case, you want javascript to do this (don't ask me how, I don't write js).

With ez-pages, you could always repeat the outline text at the top of each page. There will be a table of contents at the top of the page showing which page you are on.

14 Jan 2012, 6:40 PM
#6
mcqueeneycoins avatar

mcqueeneycoins

Zen Follower

Join Date:
Jan 2008
Posts:
156
Plugin Contributions:
0

Re: Embed php template within another php template based on drop-down menu selection?

They don't have to be php, I was just assuming that would be easiest to embed.

I'd like to keep the random text and drop down menu at the top of each page so the user can select another article if desired.

I don't mind the whole page refreshing, as long as it accomplishes the goal, but if it can be done without reloading the whole page I think it would be a better interface for the customer.

Basically I thought it would be easier to put the articles in different php files (or text files) rather than having to create a separate EZ pages.

It sounds like the EZ pages may be the only way to go.

14 Jan 2012, 7:48 PM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: Embed php template within another php template based on drop-down menu selection?

EZ-Pages would be by far the easiest way to go. You can do anything if you know how to write the code for it, but I would consider the cost/benefit ratio for different implementations of your articles content.
You could turn the table of contents into a dropdown with CSS (it might require installing the Ez-pages Improved TOC mod to have the elements to apply styling to).

14 Jan 2012, 9:43 PM
#8
mcqueeneycoins avatar

mcqueeneycoins

Zen Follower

Join Date:
Jan 2008
Posts:
156
Plugin Contributions:
0

Re: Embed php template within another php template based on drop-down menu selection?

Thanks again for the help. I've been playing around with EZpages and think this will work for what I need. I'm only creating one main page, and really don't want a separate sidebox. How can I move the link to the main EZPage to the Information sidebox?

Also, do you know if there is a way to display the TOC as a dropdown box? It's taking up too much of the page, especially if I end up having 30, 40, or more articles.

14 Jan 2012, 9:48 PM
#9
mcqueeneycoins avatar

mcqueeneycoins

Zen Follower

Join Date:
Jan 2008
Posts:
156
Plugin Contributions:
0

Re: Embed php template within another php template based on drop-down menu selection?

Never mind about the link in the Information box...the simple solution is just to turn the EZPages box into the Information box by creating internal links and then disabling the information sidebox alltogether. If you happen to know about the dropdown menu I'm still searching for a solution on that.

16 Jan 2012, 6:26 PM
#10
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: Embed php template within another php template based on drop-down menu selection?

If we can see your site with the TOC, we can give the best advice for making it a dropdown.

18 Jan 2012, 3:14 AM
#11
mcqueeneycoins avatar

mcqueeneycoins

Zen Follower

Join Date:
Jan 2008
Posts:
156
Plugin Contributions:
0

Re: Embed php template within another php template based on drop-down menu selection?

I haven't really messed with formatting, etc. since I'm still searching for my ideal solution, but you can see the page here: https://mcqueeneycoins.com/index.php?main_page=page&id=2&chapter=1

You can see the existing site and format here (final product would be similar): https://www.mcqueeneycoins.com/store/index.php?main_page=page_4

Any suggestions are greatly appreciated--thank you again for all of your help so far!

18 Jan 2012, 5:09 AM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: Embed php template within another php template based on drop-down menu selection?

You would need to install EZ-Page Improved TOC if you want to distinguish styling between the current page link and others. If you don't do that, you can still use this to make a dropdown:#navEZPagesTOCWrapper {position: relative;} #navEZPagesTOCWrapper ul {display: none;} #navEZPagesTOCWrapper:hover ul { display: block; position: absolute; background: #ffffff; border: 1px solid #aaaaaa; width: 100%; margin-left: -1px; } These selectors will also be available with the Improved TOC: ```
#navEZPagesTOCWrapper .currentPage {}
#navEZPagesTOCWrapper .notCurrentPage {}

21 Jan 2012, 5:44 PM
#13
mcqueeneycoins avatar

mcqueeneycoins

Zen Follower

Join Date:
Jan 2008
Posts:
156
Plugin Contributions:
0

Re: Embed php template within another php template based on drop-down menu selection?

Thanks again for all the assistance. I've added the code you provided but have not installed the TOC add-on. Everything seems to be working alright, but if you don't mind I have a few more formatting questions I'm having trouble with:

  1. How can I remove the <li> indention? I tried using margins on css without any success.

  2. This may be a long shot, but is there anyway to make it appear like the select options dropdown? Where there is a box that says "Select Article..." and then when you click/hover the list appears. Maybe I could change the TOC text to read Select Article and create a border around that or something?

Thanks again!