[Resolved] DataTables & Smarty

[Resolved] DataTables & Smarty

david63david63 Posts: 7Questions: 0Answers: 0
edited September 2012 in DataTables 1.9
This is possibly not a DataTables problem but more of a Smarty templating problem but I am hoping someone may be able to se what is going wrong (because I cannot and I have spent all day looking at it!)

Right then - I have been going along converting a standard PHP/Smarty set up to use dataTables and all has gone well until ...

I have the following within my Smarty template

[code]
$(document).ready(function() {
$('#example').dataTable( {
'bProcessing': true,
'bServerSide': true,
'bStateSave': false,
'bAutoWidth': true,
'bScrollCollapse': true,
'iDisplayLength': 10,
'sDom': 'W<"clear">ltipr',
'sPaginationType': 'full_numbers',
'sAjaxSource': './../test/data_test.php',
'oColumnFilterWidgets': {
'aiExclude': [0]
},
'aaSorting': [
[4, 'asc'],
[5, 'asc'],
[1, 'asc'],
],
'aoColumnDefs': [
{'aTargets': [0], 'bVisible': false},
{'aTargets': [4], 'bVisible': false},
{'aTargets': [5], 'bVisible': false},
],
});
});
[/code]


The problem that I have is with the

[code]'aoColumnDefs': [
{'aTargets': [0], 'bVisible': false},
{'aTargets': [4], 'bVisible': false},
{'aTargets': [5], 'bVisible': false},
],[/code]

part of the code. Everything else works fine but this bit of the code is generating a Smarty error (the crucial part being)

[quote]on line 31 ";{'aTargets': [0], 'bVisible': false}," - Unexpected ";: ", expected one of: ";}" , "" , ATTR'[/quote]


No matter what I do I cannot see what is causing the problem. I have tried:
- double/single quotes
- square/round/curly brackets
- surrounding various parts of the code with "" tags
- changing the order of the items

If I remove the "{}" from that part of the code then Smarty likes it but, obviously, DataTables does not.

If I remove that part of the code then everything works as it should but the columns are not hidden.

The same problem exists with "aoColumns".

I am using the latest version of DataTables (1.9.4) and the latest version of Smarty (3.1.12)

I cannot post a link as this is being run on my local machine.

Any advice, other than stop using Smarty, would be appreciated.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited September 2012
    The problem is that Smarty seems the `{` as a variable, but it is intact a Javascript object. Just found this on a quick Google: http://www.smarty.net/forums/viewtopic.php?t=150 . Another option might be to put a space before and after each brace or possibly to change Smarty to use a double brace.

    Other thing I notice is that you have a trailing comma in each of your arrays - IE will reject that.

    Allan
  • david63david63 Posts: 7Questions: 0Answers: 0
    Thanks Allan - I had not found that link that particular link.

    For anyone else encountering this problem I found that using [code]{ldelim} {rdelim}[/code] tags solved the problem.

    Thanks also for the IE advice (just wish IE would use the standards!)

    Right then onwards and upwards to find the next problem!!!
This discussion has been closed.