asdasdasdfsdfsdfsdf Posted April 12, 2017 Posted April 12, 2017 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.
xtech Posted April 12, 2017 Posted April 12, 2017 52 minutes ago, Lavenblade said: I can't even preform a while statement in PHP, and it looks really messy. You can, but you should use the alternate syntax. Yes it's messy, i agree with you.
asdasdasdfsdfsdfsdf Posted April 12, 2017 Author Posted April 12, 2017 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.
xtech Posted April 12, 2017 Posted April 12, 2017 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.
asdasdasdfsdfsdfsdf Posted April 12, 2017 Author Posted April 12, 2017 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'); } } ) );
asdasdasdfsdfsdfsdf Posted April 13, 2017 Author Posted April 13, 2017 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) );}}
BomAle Posted April 13, 2017 Posted April 13, 2017 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.
asdasdasdfsdfsdfsdf Posted April 13, 2017 Author Posted April 13, 2017 I'll give that a shot, thanks! I've tried using a PHP Block but if I use anything other than PHP it seems t throw an http 500 error. =(
asdasdasdfsdfsdfsdf Posted April 14, 2017 Author Posted April 14, 2017 @BomAle Your solution with external PHP files and including them worked flawlessly. I spoke with 3 or so different support staff and none of them could give me any kind of answer. Thank you very much.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.