Jump to content

IP.Pages & Raw PHP


Recommended Posts

Hello,

The templating system for IP.Pages is really, really bad for complex websites that make use of PHP. I can't even preform a while statement in PHP, and it looks really messy.

Is there a way I can write an entire page using raw HTML, CSS, JS, and PHP without using the templating engine? Someone mentioned using blocks, but including external scripts, styles, etc seemed to generate errors. I just want a functional way to write traditional pages using IP.Pages. I prefer to not rely on the Marketplace as I want native functionality.

Link to comment
Share on other sites

1 minute ago, xtech said:

 

You can, but you should use the alternate syntax. Yes it's messy, i agree with you.

I couldn't get any function that required curly brackets to work. Could you please provide an example on how I'd write in using the templating system?

For example, I was unable to write the following as I am not sure how:

while ($row = $result->fetch_assoc()) {
  //More code here
}

I tried something along the lines of:

{{while ($row = $result->fetch_assoc())}}
{{ { }}
//More code here between {{ and }}
{{ } }}

Also, why is this alternate syntax the way we should be writing PHP? =(

Does anyone know why the PHP code wont indent like the rest of the HTML in the editor? I'm also having a indentation crisis. =/

I'm grateful for any and all insight into this.

Link to comment
Share on other sites

Something like this will do:

{{while ($row = $result->fetch_assoc()):}}

<!-- put the code here -->

{{endwhile;}}	

 

3 minutes ago, Lavenblade said:

Also, why is this alternate syntax the way we should be writing PHP? =(

Dunno, maybe because you can have your template variables displayed by typing {$varname}

4 minutes ago, Lavenblade said:

Does anyone know why the PHP code wont indent like the rest of the HTML in the editor? I'm also having a indentation crisis. =/

 

The editor is 3rd party, i guess it messes up with the template logic php IPS uses.

Link to comment
Share on other sites

How do I go about defining a function using the IPS syntax? I'm not sure how to do a callback either for custom validation using Form Helper.

As seen in the documentation:

$form->add( new \IPS\Helpers\Form\Number( 'my_field', NULL, TRUE, array(), function( $val )
{
	if ( $val == 7 )
	{
		throw new \DomainException('form_bad_value');
	}
} ) );

 

Link to comment
Share on other sites

I managed to get validation working, but doing it this way in one line will not work for my needs as I need to preform a database query for this custom validation. How can I do this using multiple lines?

{{$validate_username = function($data){ if($data == "1") { throw new \InvalidArgumentException('some_lang_string'); } };}}
{{$form->add( new \IPS\Helpers\Form\Text('Username', null, TRUE, array('minLength' => 1, 'maxLength' =>23), $validate_username, null, null) );}}

 

Link to comment
Share on other sites

I suggest to write the code inside another php file or template and try to eval it ... with try/catch this is similar to plugin workflow. (or to see also {include=""} tag)

{insert="$filename"}


Includes a PHP script file

Parameters
$filename - The filename of the PHP file to include. The output of the file is buffered and output.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...