PDA

View Full Version : Multiple language menu in template


CraigR
09-08-2011, 04:27 AM
I am creating a multiple language site, and as such, am using a session variable to select which menu to load.

The block I added to my template is as follows…

<div id="topNavigation">
<?php switch ($_SESSION['language']) {
case 'english': //use the english menu
require_once("../CSSMenuWriter/cssmw/menu.php");
break;
case 'spanish': //use the spanish menu
require_once("../CSSMenuWriter/cssmw/spanish/menu.php");
break;
case 'mandarin': //use the mandarin menu
require_once("../CSSMenuWriter/cssmw/mandarin/menu.php");
break;
case 'hindi': //use the hindi menu
require_once("../CSSMenuWriter/cssmw/hindi/menu.php");
break;
default: //use the english menu
require_once("../CSSMenuWriter/cssmw/menu.php");
}
?>
</div>


Any pages based on this template which occur in a subfolder, work perfectly, the code above is inserted exactly as above onto my page.

However, pages in the root folder, based on the same template do not work properly, the menu block appears as follows, with the first require line (only) missing the leading ../

I would expect all of the require lines to point to CSSMenuWriter...

<div id="topNavigation">
<?php switch ($_SESSION['language']) {
case 'english': //use the english menu
require_once("CSSMenuWriter/cssmw/menu.php");
break;
case 'spanish': //use the spanish menu
require_once("../CSSMenuWriter/cssmw/spanish/menu.php");
break;
case 'mandarin': //use the mandarin menu
require_once("../CSSMenuWriter/cssmw/mandarin/menu.php");
break;
case 'hindi': //use the hindi menu
require_once("../CSSMenuWriter/cssmw/hindi/menu.php");
break;
default: //use the english menu
require_once("../CSSMenuWriter/cssmw/menu.php");
}
?>
</div>



I could create another template specifically for files in the root folder, but this seems daft. Is there something else i can do ?

Jason Byrnes
09-08-2011, 06:41 AM
why not use Framework Builder. Add the menus as a dynamic plugin, framework builder will automatically adjust the require paths for you.

CraigR
09-08-2011, 07:01 AM
I think I am too far down the line with this project.

If the multi-lingual aspect was part of the original plan, I may have gone down this route

Jason Byrnes
09-08-2011, 10:52 AM
looks like this is an issue when you have multiple require_once() statements in the same PHP block. The work around is to create a unique php block for each require_once:


<?php switch ($_SESSION['language']) {
case 'english': //use the english menu
?>
<?php
require_once("../CSSMenuWriter/cssmw/menu.php");
?>
<?php
break;
case 'spanish': //use the spanish menu
?>
<?php
require_once("../CSSMenuWriter/cssmw/spanish/menu.php");
?>
<?php
break;
case 'mandarin': //use the mandarin menu
?>
<?php
require_once("../CSSMenuWriter/cssmw/mandarin/menu.php");
?>
<?php
break;
case 'hindi': //use the hindi menu
?>
<?php
require_once("../CSSMenuWriter/cssmw/hindi/menu.php");
?>
<?php
break;
default: //use the english menu
?>
<?php
require_once("../CSSMenuWriter/cssmw/menu.php");
?>
<?php
}
?>

CraigR
09-08-2011, 11:10 AM
thanks Jason, I'll try that.

This would be a real p.i.a. if it was a big code block

Is this a bug in dreamweaver ?

Jason Byrnes
09-08-2011, 11:36 AM
it appears to be.

as a test i created a template with multiple require once lines to the same file:

<?php
require_once("../phpinfo.php");
require_once("../phpinfo.php");
require_once("../phpinfo.php");
?>
<?php
require_once("../phpinfo.php");
require_once("../phpinfo.php");
?>
<?php
require_once("../phpinfo.php");
?>
<?php
require_once("../phpinfo.php");
?>
<?php
require_once("../phpinfo.php");
?>


when i applied this to a page, the results was:

<?php
require_once("phpinfo.php");
require_once("../phpinfo.php");
require_once("../phpinfo.php");
?>
<?php
require_once("phpinfo.php");
require_once("../phpinfo.php");
?>
<?php
require_once("phpinfo.php");
?>
<?php
require_once("phpinfo.php");
?>
<?php
require_once("phpinfo.php");
?>


It seams Dreamweaver will only alter the path of the first require_once() statement in an individual php code block.

CraigR
09-08-2011, 12:14 PM
thanks for testing that out Jason.

I just did the same and got the same result.

putting the code into separate blocks is a good workaround, so i have done it for the 2 menus and the footer, which appears to work fine.

the workaround is (obviously) only needed for the template, when using my php switch block within a page, it works asis.

Thanks again for your help