Jump to content

Use a variable in one page to determin links in another?


garek007

Recommended Posts

Hi,

 

I'll try to explain this as best I can.

 

I have a document that gets included into another document. 

 

This document is a navigation pane and simply holds links to other documents.

 

I'm wondering if I can define a variable in the page that my navigation document is linking to and use that variable to set the text using an echo statement in the navigation document.

 

See it seems weird, seems like a loop.  I want the document that it links to, to define the link itself. Can that be done?

 

Thanks,

Stan

Link to comment
Share on other sites

so...let me see if i can get this straight...you have index.php, which includes nav.php. nav.php has a bunch of links, one of which points to page.php. In page.php you have a variable called $title and it is set to "This is a page". you are wondering if it is possible to access that variable via loading index.php with nav.php included?

 

no, you cannot. i assume you are trying to do something along the lines of getting the title of the page dynamically so you don't have to update it in two places. the only way to accomplish this is to have a central file that defines it that both nav.php and page.php include. for instance, you can have a file called config.php and in it:

<?php
  $page_titles['page.php'] = "This is a page";
?>

then, you can include this file wherever you want and have access to that data.

 

does that help?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.