XF 1.0 Editing Templates and Defining a Callback for Pages

When we debuted the Pages feature, it was intended to be a simple way to get some custom HTML onto a page surrounded by the standard XenForo user interface chrome. By the time we reached Beta 1, it had evolved into an altogether more powerful system.

Pages now support a PHP callback, so your pages can request data from the database and be used as a platform for building any kind of single-page application you might want to build. They also allow you to override the default and specify your own template to be rendered by the page, so the possibilities really are limitless.

This two-part video shows you the basics of building a simple application using the Pages system, and delves into the realms of the template editor to create and edit the custom HTML that will be used to display your page.

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

Having built a basic dynamic page, in this second part we add more functionality and data to the page including a sidebar and a list of the authors of the most recent posts. In doing so, we look into advanced template syntax use, and reveal one of XenForo's hidden treasures.

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

Part 3
I've just uploaded a third part, answering some questions that have come up:

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.

... and created a new answer post here:
http://xenforo.com/community/threads/random-questions-answered.114/page-2#post-102179
 
Yes, in your callback code:
PHP:
$t = $controller->_input->filterSingle('t', XenForo_Input::STRING);

$s = $controller->_input->filterSingle('s', XenForo_Input::UINT);
 
I feel thick (no change there then!)

I've enabled debug mode, get prompted for a username and password, but it's always rejected as incorrect.

I've tried creating new users, reseting passwords and nothing seems to kick in - any ideas?
 
I feel thick (no change there then!)

I've enabled debug mode, get prompted for a username and password, but it's always rejected as incorrect.

I've tried creating new users, reseting passwords and nothing seems to kick in - any ideas?
I can think of a couple of things:

1) Are you sure you're getting a no permission login error, or is it failing to connect for another reason? Try connecting with your web browser to {xenforo}/admindav.php/ first.

2) Is admindav.php on a site protected by .htaccess password protection? They both use HTTP Basic Auth, and can not co-exist.
 
I am using Transmit to map the WebDAV connection to a virtual drive. That allows me to open all files with Textmate as if they were on my local drive.
It's working fine but the saving takes up to 10 seconds. If I happen to reload the page while the template is saving, the layout is broken and sometimes the content of the template gets lost.

I don't know if it's Textmate, Transmit or XenForo - does anyone else have this slow saving problem?
 
I can think of a couple of things:

1) Are you sure you're getting a no permission login error, or is it failing to connect for another reason? Try connecting with your web browser to {xenforo}/admindav.php/ first.

2) Is admindav.php on a site protected by .htaccess password protection? They both use HTTP Basic Auth, and can not co-exist.

Hi there I have similar problems with connecting to my XenForo. My Dreamweaver says wrong password or username. I have checked the URL manually (http://www.onlinegilde.net/admindav.php/). The URL worked fine and the login form pop up. When I type there my username and password and press enter it only shows up this dialog again.

Dreamweaver always says Wrong username and password. But I am absolutly sure that I have typed in the correct username and password.

Any suggestions how to solve this problem?

Thanks a lot!
 
I can think of a couple of things:

1) Are you sure you're getting a no permission login error, or is it failing to connect for another reason? Try connecting with your web browser to {xenforo}/admindav.php/ first.

2) Is admindav.php on a site protected by .htaccess password protection? They both use HTTP Basic Auth, and can not co-exist.

Like pjfry, Dreamweaver is returning the error Wrong Username and Password and using my browser (both IE and Firefox) just keep returning the login box.

The admindav.php doesn't have any other .htaccess above it apart from the default xenforo one.
 
I'm having similar problems like ijeffers and pjfry.
Took a look at the script and did some googling but I'm not sure if I understand things correctly.

But I read on a couple of places that HTTP Basic authentication with PHP can't be used if you're running PHP as a CGI?
If that's true, that you must run PHP as a server module, then that is probably my problem.

Unfortunately I didn't figure out how to change that on my local server installation last night so I haven't tested this as much as I would want to.

/SK
 
Think pjfry has hit the nail on the head, it's cgi mode that's causing the problem.

Tried to create a .htaccess rule based of SabreDav but it didn't make any difference:

Code:
RewriteRule .* /admindav.php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

SabreDav says you should use this, but not sure if Server.php is the admindav or the Server.php hidden away in the library:

If you use PHP through CGI or FastCGI and Apache authentication headers are not passed through by default. You can enable this with the following mod_rewrite rule:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
If you already had a mod_rewrite rule to map all urls to a server file, you might need to change this to something like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* /server.php [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
Note the /server.php. Make sure this reflects the correct location of your server file

Bunged my admin details into the array in admindav.php and it connected straight away (but obviously not a very clever idea!!!!)

Don't know if there's another way to pass the auth information to admindav.php or if there's another file which needs the auth details passing too or whether my modified rule is just cack!

Any ideas Kier?

I can think of a couple of things:

1) Are you sure you're getting a no permission login error, or is it failing to connect for another reason? Try connecting with your web browser to {xenforo}/admindav.php/ first.

2) Is admindav.php on a site protected by .htaccess password protection? They both use HTTP Basic Auth, and can not co-exist.

Hi there I have similar problems with connecting to my XenForo. My Dreamweaver says wrong password or username. I have checked the URL manually (http://www.onlinegilde.net/admindav.php/). The URL worked fine and the login form pop up. When I type there my username and password and press enter it only shows up this dialog again.

Dreamweaver always says Wrong username and password. But I am absolutly sure that I have typed in the correct username and password.

Any suggestions how to solve this problem?

Thanks a lot!

Like pjfry, Dreamweaver is returning the error Wrong Username and Password and using my browser (both IE and Firefox) just keep returning the login box.

The admindav.php doesn't have any other .htaccess above it apart from the default xenforo one.
 
Don't know if there's another way to pass the auth information to admindav.php or if there's another file which needs the auth details passing too or whether my modified rule is just cack!
I'm facing the same problem running Zend Server CE. (PHP as CGI/FastCGI)
This additional rule seems to fix it...
Rich (BB code):
RewriteEngine On
RewriteRule ^admindav.php - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},NC,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data|js|styles|install) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
 
I'm facing the same problem running Zend Server CE. (PHP as CGI/FastCGI)
This additional rule seems to fix it...
Rich (BB code):
RewriteEngine On
RewriteRule ^admindav.php - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},NC,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data|js|styles|install) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

That sorted it, cheers Shadab! Right rule, wrong place (stupid SaberDav instructions!!)
 
I'm facing the same problem running Zend Server CE. (PHP as CGI/FastCGI)
This additional rule seems to fix it...
Rich (BB code):
RewriteEngine On
RewriteRule ^admindav.php - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},NC,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data|js|styles|install) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Yep, that did it for me too. Thanks!

/SK
 
Hi there sorry for the late reply. After a lot of testing I can say, yes this problem is because of CGI / Fast CGI. So I have tested this Code on my site:

Code:
RewriteRule ^admindav.php - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},NC,L]

But it didn't worked. Then I tested another hoster, there the some Code worked. So I am not sure why one time the code work und sometimes not. So I contaced my first hoster and told him the problem. Now he is testing. As soon I get an answer from my hoster I will post it here. So maybe someone has the some problem.

Greetings

Benny
 
Anyone know how to connect webdav up on a htaccess protected domain? Seems to be struggling to connect and I didnt really want to remove htaccess auth before we're ready :(

I don't believe that's actually possible, as both htaccess and WebDAV use HTTP Basic Auth.

If your client supports it you can probably do
Code:
user:pass@host
for the host. That will satisfy htaccess credentials. I've done this before using simple PHP/curl.

I'm not entirely certain if this will work in your case, but it's worth a shot?
 
Great tutorial Kier, I loved the second video highlighting some of the intuitive nuances of XenForo's template system. Very informative!
 
Back
Top Bottom