在Joomla中设置列宽的基本PHP [英] Basic php to set column width in Joomla

查看:132
本文介绍了在Joomla中设置列宽的基本PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有引导程序的Joomla创建Joomla模板.我有一个3列的布局(容器总计12个,所以Bootstrap:span12).我在Joomla后端中设置参数以设置$ left和$ right列宽,然后在模板中回显这些变量以设置左和右div列宽(在index.php中)

I am using Joomla with bootstrap to create a Joomla template. I have a 3 column layout (container totalling 12 so Bootstrap: span12). I am setting parameters in the Joomla backend to set the $left and $right column widths and then echoing those variables in my template to set the left and right div column widths (in index.php)

但是,我想在模板中使用简单的逻辑,根据后端参数中输入的$ left和$ right值自动计算和设置中间列的跨度值.

However, I want to use a simple bit of logic in my template to automatically calculate and set the span value of the middle column based on the $left and $right values entered in the parameters in the backend.

我从字面上知道几乎为零的PHP,所以请原谅我这段代码的粗鲁.我只想检查我的操作是正确的还是愚蠢的,或者是否有更好的方法.这就是我在做什么...

I literally know almost zero PHP so please forgive me for the crudeness of this code. I just want to check if what I am doing is correct or plain stupid or if there is a better way. Here's what I am doing...

<?php
$left = $this->params->get('sidebarLeftWidth', '');
$right = $this->params->get('sidebarRightWidth', '');

$grid = 12;
$span = $grid - ( $left + $right );
?>

然后在我的html中设置中间列的宽度-只需...

and then to set the width of my middle column in my html - simply...

class="span<?php echo $span; ?>"

推荐答案

如果正确设置参数,看起来应该可以使用.

Well, that looks like it should work, if you have set the parameters correctly.

您实际上并没有说出问题出在哪里,即正在生成什么结果,因此很难确切地知道,所以这里有一些背景信息和建议可以帮助您弄清楚.对于模板开发,您可以在 Joomla Docs 网站上找到更多信息. joomla.org/Template_Development"rel =" nofollow>模板开发.

You don't actually say what's going wrong, i.e. what result is being generated so it's a bit hard to tell exactly, so here's some background info and suggestions that may help you figure it out. For template development you can find more at the Joomla Docs website on Template Development.

假设您的代码位于模板index.php中:

Assuming your code is in your templates index.php:

  1. $this->params->get('sidebarLeftWidth','')正在获取名为sidebarLeftWidth的模板参数,但是如果该参数不可用,则将其有效地设置为'' null.

  1. $this->params->get('sidebarLeftWidth','') is getting a template parameter called sidebarLeftWidth, but if that parameter isn't available then it's setting it to '' effectively null.

get中的参数名称应使用与templateDetails.xml文件中完全相同的拼写和大写字母进行定义.如果不是,您的$left$right可能为空. (如果您将问题编辑为包括模板XML或模板XML的一部分,将会很有帮助.)

The parameter names in your get should be defined with exactly the same spelling and capitalisation as in your templateDetails.xml file. If not your $left and $right may be empty. (It will help if you edit your question to include the template XML, or part of it.)

params部分是 JRegistry对象并返回混合类型,具体取决于对象的name属性中最初存储的内容(通常是字符串,但是可以是PHP可以处理的任何内容).要强制使用in值,您可能需要更改get行以将结果转换为整数,如果未找到则返回0:

The params part is a JRegistry object and returns a mixed type depending on what is originally stored in the name attribute of the object (usually this is a string, but it could be anything PHP can handle). To force an in value you may want to change your get lines to cast the results as integers and return 0 if nothing is found:

$left = (int) $this->params->get('sidebarLeftWidth', 0);

$right = (int) $this->params->get('sidebarRightWidth', 0);

在调试器中检查params的内容,即检查$this->params对象中每个命名参数的值.如果您不使用IDE,请尝试执行print_r():

Check the contents of your params in your debugger, i.e. check the values of each of your named parameters in the $this->params object. If you're not using an IDE try doing a print_r():

echo '<pre>' . print_r($this->params, true) . '</pre>';

这篇关于在Joomla中设置列宽的基本PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆