how use parameters in the path-string - symfony

I am using Symfony2 and TWIG. With "path" I will open a second page and set some parameters.
{% set place = "The City" %}
<tr>
<td class="tdstellenangebot_zelle">
<a href="#" onclick="anzeige_job('{{ path("_anzeige_job",{kznr:102,ort:"unseren Standort in " {{ place }} ,filiale:1} ) }}')">
The jobdescription
</a>
</td>
<td class="tdstellenangebot_zelle textBold">{{ place }} </td>
</tr>
But the script dont work.
How can I set the place in the path with the variable ?
Thanks alot for your help.

You need simple concatenation:
{% set place = "The City" %}
<tr>
<td class="tdstellenangebot_zelle">
<a href="#" onclick="anzeige_job('{{ path("_anzeige_job", { kznr: 102, ort:"unseren Standort in " ~ place, filiale: 1 }) }}')">
The jobdescription
</a>
</td>
<td class="tdstellenangebot_zelle textBold">{{ place }} </td>
</tr>
Take a look at tilde sign ~. It is like + in JavaScript and . in PHP and is used to concatenate strings.

Related

printing the text of the select element from composite instead of key

I am trying to iterate and print the text of the select element selected by the user. The key of the composite is item.
{% for item in data.item %}
<tr>
<td style="text-align: center;">{{ item.qty }} </td>
<td style="text-align: center;">{{ item.book }}</td>
</tr>
{% endfor %}
I know that item.book would only print the key. So how would I change it to print the text?

Hide and Show 'ng-repeat' Table Row Using Contextual Menu

I am creating a table adding row dynamically into the table. I want to hide selected row by providing a contextual menu.
I have created the html and model to show contextual menu but I don't how to call double click. I am able to create a contextual menu with this but now able to pass the selected row index into the function so that i can use that index to show or hide.
Data in table row is of 2 type, if i am getting data from backend then I am displaying that data in row but data not present then I am adding input element in cell of the table row. So I want to create 2 different contextual menu to work on 2 different rows one with data from database and other one with input textbox.
I want to add contextual menu on Row with background color grey which has hide option and the contextual menu on row with background will add that row that to other page.
HTML
<table id="phaseTable" class="table table-bordered">
<thead id="phaseHead">
<tr>
<th id="phase" scope="col" class="textSize grey t-space th-border">{{'eox.label.phases.phase'| localize}}</th>
<th id="description" scope="col" class="textSize grey th-border">{{'eox.label.phases.description'| localize}}</th>
<th id="knowHow" scope="col" class="textSize grey th-border">{{'eox.label.phases.how'| localize}}</th>
</tr>
</thead>
<tbody id="phaseBody">
<tr context-menu data-target="phase-row-hide" data-ng-repeat="pointCle in jes.listePointCle" id="{{$parent.$id+'-'+$index}}"
data-ng-click="setRowSelected($parent.$id,$index)">
<td id="phaseData" nowrap="nowrap" align="center" class="textSize grey t-space td-border"
data-ng-if="pointCle.type.length > 0">{{pointCle.type}}
</td>
<td id="phaseData" nowrap="nowrap" align="center" class="t-space td-border"
data-ng-if="pointCle.type == undefined || pointCle.type.length == 0 || pointCle.type.length == ''">
<input type="text" name="phaseData" maxlength="10" size="5" value="100" style="text-align: center;" class="input-how">
</td>
<td id="descriptionData" class="textSize grey t-space td-border"
data-ng-if="pointCle.designation.length > 0">{{pointCle.designation}}
</td>
<td id="descriptionData" class="t-space td-border"
data-ng-if="pointCle.designation == undefined || pointCle.designation.length == 0 || pointCle.designation.length == ''">
<input id="descriptionData{{$index}}"type="text" name="descriptionData" maxlength="50" size="50" value="OC BLA BLA" class="input-how"
data-ng-keypress="addRowPhaseOnPress($index)">
</td>
<td id="knowHowData" class="textSize grey t-space td-border"
data-ng-if="pointCle.risque.length > 0">{{pointCle.risque}}
</td>
<td id="knowHowData" class="t-space td-border"
data-ng-if="pointCle.risque == undefined || pointCle.risque.length == 0 || pointCle.risque.length == ''">
<input type="text" name="knowHowData" id="knowHowData" size="50" maxlength="50" class="input-how">
</td>
</tr>
</tbody>
</table>
Model
<div class="position-fixed" id="phase-row-hide">
<ul class="dropdown-menu" role="menu">
<li>
<a class="pointer" role="menuitem" tabindex="1" data-ng-click="setRowSelected()">
Hide Row
</a>
</li>
</ul>
JS - Code to select the row
$scope.setRowSelected = function(id,index){
alert('id = '+id);
alert('index = '+index);
alert('rowId = '+id+'-'+index);
$scope.selectedRow = index;
}
Screen Display
Context menu directive:
app.directive("contextMenu", function() {
return {
link: postLink
};
function postLink(scope, elem, attrs) {
elem.on("contextmenu", function (e) {
scope.$apply(function() {
var locals = {$event: e, $scope: scope, $element: elem};
scope.$eval(attr.contextMenu, locals);
});
});
}
})
Usage:
<tr context-menu="onContext($event, $index)" ng-repeat="...
$scope.onContext = function(ev, index) {
ev.preventDefault();
console.log(index);
//...
};
For more information, see
MDN Web API Reference - contextmenu Event

Mistake Arguments must be separated by a comma. Unexpected token "punctuation" of value

{% for item in product %}
<tr>
<td class="col-lg-5" > <h5> {{ item.tensp}}</h5></td>
<td class="col-lg-12"> {{ item.thanhphan}}</td>
<td class="col-lg-12"> {{ item.gia}}</td>
line 19 <td class="col-lg-12"> <img src="{{asset('/bundles/image/'{item.hinh})}}" alt=""/></td>
</tr>
{% endfor %}
I got this error message in Symfony Arguments must be separated by a comma. Unexpected token "punctuation" of value "{" ("punctuation" expected with value ",") in SP\findall.html.twig at line 19.
how can i fix it
Try concat string with ~ operator.
{% for item in product %}
<tr>
<td class="col-lg-5" ><h5> {{ item.tensp}}</h5></td>
<td class="col-lg-12">{{ item.thanhphan}}</td>
<td class="col-lg-12">{{ item.gia }}</td>
<td class="col-lg-12"><img src="{{ asset('/bundles/image/' ~ item.hinh)}}" alt=""/></td>
</tr>
{% endfor %}

Need advices with Symfony2

I've understood the routing principle consisting in creating routes and call them from twig templates.
When calling, we can pass parameters to the route which will be included in the url.
I'm in the following case, I have an object called "Object" and each object can belong to other objects called "Category".
In my twig template, I display all my objects line by line (each row contains the object information and a checkbox to select it).
I have also a button "send", I'd like to click this button and edit all the selected objects.
However I don't think I can do this with a route because I don't know by advance how many elements will be selected (so I don't know the number of parameters to the route).
I'd like to know how you would do this.
Sorry for the tardive response, I have the following code in my twig tempalte :
<table class="table table-bordered table-condensed table-stripped">
<tr>
<td> Delete </td>
<td> Title </td>
<td> Date added </td>
<td> Description </td>
<td> </td>
</tr>
{% for link in links %}
<tr>
<td>
<a class="btn" href="{{ path('ProjectTestBundle_deleteLink', {'idLink': link.id}) }}"><i class="icon-trash"></i></a>
</td>
<td> <a>{{link.title}}</a> </td>
<td> {{link.dateAjout|date('Y-m-d H:i:s')}} </td>
<td> {{link.description}} </td>
<td>
<input id="{{link.id}}" type="checkbox"">
</td>
</tr>
{% endfor %}
</table>
<a class="btn">
<i class="icon-edit"></i>
Add selected links to a theme
</a>
What I'd like to is to put a href attribute there
<a href="" class="btn">
<i class="icon-edit"></i>
Add selected links to a theme
</a>
and call a path with all the links selected with the checkbox.

jquery select span by id

hello guys
some times you just loose it and you cant event remember how to search that that you lost
<div>
<table cellspacing="0" rules="all" border="1" id="ctl00_DefaultContent_migrationGridView" style="height:90%;width:100%;border-collapse:collapse;">
<tr>
<th scope="col"> </th><th scope="col">Lenda</th><th scope="col">CSV Dosje</th><th scope="col">Gjendje</th><th scope="col">Datë</th><th scope="col">Njoftim</th><th scope="col"> </th>
</tr><tr>
<td>
<input type="submit" name="ctl00$DefaultContent$migrationGridView$ctl02$Button1" value="Fshije" id="ctl00_DefaultContent_migrationGridView_ctl02_Button1" />
</td><td>
<a id="ctl00_DefaultContent_migrationGridView_ctl02_CaseLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl02$CaseLinkButton','')" style="font-weight:bold;">mig1</a>
</td><td>
<span id="ctl00_DefaultContent_migrationGridView_ctl02_lblCSVFileName">19_71914066_2010-11-11_0849_ENG_SOFALI.csv</span>
</td><td>
<span id="ctl00_DefaultContent_migrationGridView_ctl02_Label2" style="color:Maroon;font-weight:bold;">Read</span>
</td><td>2010-12-28</td><td>
<span id="ctl00_DefaultContent_migrationGridView_ctl02_Label3"></span>
</td><td>
<a id="ctl00_DefaultContent_migrationGridView_ctl02_startStopLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl02$startStopLinkButton','')">Start migration</a>
<a id="ctl00_DefaultContent_migrationGridView_ctl02_checkedAllLinkButton" title="Të Kontrolluara" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl02$checkedAllLinkButton','')">Të Kontrolluara</a>
</td>
</tr><tr>
<td>
<input type="submit" name="ctl00$DefaultContent$migrationGridView$ctl03$Button1" value="Fshije" id="ctl00_DefaultContent_migrationGridView_ctl03_Button1" />
</td><td>
<a id="ctl00_DefaultContent_migrationGridView_ctl03_CaseLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl03$CaseLinkButton','')" style="font-weight:bold;">mig1</a>
</td><td>
<span id="ctl00_DefaultContent_migrationGridView_ctl03_lblCSVFileName">19_71914070_2010-11-11_0850_ENG_TRUDE.csv</span>
</td><td>
<span id="ctl00_DefaultContent_migrationGridView_ctl03_Label2" style="color:Maroon;font-weight:bold;">Read</span>
</td><td>2010-12-28</td><td>
<span id="ctl00_DefaultContent_migrationGridView_ctl03_Label3"></span>
</td><td>
<a id="ctl00_DefaultContent_migrationGridView_ctl03_startStopLinkButton" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl03$startStopLinkButton','')">Start migration</a>
<a id="ctl00_DefaultContent_migrationGridView_ctl03_checkedAllLinkButton" title="Të Kontrolluara" href="javascript:__doPostBack('ctl00$DefaultContent$migrationGridView$ctl03$checkedAllLinkButton','')">Të Kontrolluara</a>
</td>
</tr>
</table>
</div>
can somebody tell me how to iterate through spans that have this string on the id 'lblCSVFileName'
and get their values
for the first row i should get 19_71914066_2010-11-11_0849_ENG_SOFALI.csv and for the second
19_71914070_2010-11-11_0850_ENG_TRUDE.csv
:( another bad day
You can use an attribute ends-with selector for the ID and .map() to get an array of strings (the text inside each), like this:
var arr = $("span[id$='lblCSVFileName']").map(function() {
return $(this).text();
}).get();
Or, a slightly more optimized unpublished version:
var arr = $("span[id$='lblCSVFileName']").map(function() {
return $.text([this]);
}).get();
This would get you an array of values to work with, for example:
["19_71914066_2010-11-11_0849_ENG_SOFALI.csv", "19_71914070_2010-11-11_0850_ENG_TRUDE.csv"...]
The following code will give you what you need.
It gets all spans that have an ID that starts with "ctl00_DefaultContent_migrationGridView_ctl02_".
$('span[id^="ctl00_DefaultContent_migrationGridView_ctl02_"]').each(function() {
//the following will give you the text of each span
$(this).text();
});
NOTE: I would add a class to each span and do a jquery select using that.

Resources