Expression Engine: How do I display the category name of an entry? - expressionengine

I am using SafeCracker to create some entries on a site and when the form is submitted it comes up in a preview template.
I need to be able to display the selected category for the entry.
I am using the following code to display the results in the preview template:
{exp:safecracker channel="jobs" id="contact" return="jobs/preview/ENTRY_ID" entry_id="{segment_3}"}
<p>Job Type: {job_type}<br />
Category: {exp:channel:category_heading}{category_name}{/exp:channel:category_heading}<br />
Location: {job_location}</p>
<p>Description:<br />
{job_description}
</p>
<p>Apply by: {how_to_apply} at: {apply_value}</p>
<p>Company: {company}</p>
<p>Description: <br />
{company_description}</p>
{/exp:safecracker}
As it is, the Category: value is blank. What is the correct way to do this?
Thanks!

Use: {categories}{if selected}{category_name}{/if}{/categories}.
Failing that, you could use the query module:
{exp:query sql="
SELECT c.cat_name
FROM exp_categories c, exp_category_posts cp
WHERE cp.entry_id = {segment_3}
AND c.cat_id = cp.cat_id
" backspace="2"}{cat_name}, {/exp:query}

Related

Dynamically assign value to Submit button in MVC

I have a mvc program which can be run in 2 environments dev and prod.
I referred to this program in https://www.codeproject.com/Articles/17660/Single-web-config-file-across-all-environments-dev and attached
ConfitIt.dll to my MVC program. In Global.asax.cs and Application_Start method, I included
String environment = EnvironmentSettings.Environment;
In the Index.cshtml, I have a button whose value needs to change depending on environment
I want it to display "Push to" + whatever environment it's in
This is the code I have
<input type="submit" value="Push to" +EnvironmentSettings.Environment style="height:40px; width: 60px;font-weight: bold;background-color:#b6ffff; " /> <br />
I know this is wrong because I don't see the value. I tried this
#Html.Label("dynamic settings", EnvironmentSettings.Environment)
and I see the correct value
How can I do this or is there an alternate way instead of ConfigIt.dll?
Thanks
MR
Write as follows:
<input type="submit" value='#("Push to" + EnvironmentSettings.Environment)' style="height:40px; width: 60px;font-weight: bold;background-color:#b6ffff; " /> <br />

Put linebreak/newline in tooltip

I'd like to put a linebreak in a tooltip so that it displays like:
Nom: value1
Quality: value2
I tried:
1.
<h:outputText title="Nom: #{cntc.value1}<br/>Quality: #{cntc.value1}" />
2.
<h:outputText title="Nom: #{ (''.concat(cntc.value1).concat('<br/>')concat('Quality: ').concat(cntc.value2)}" />
None of them worked for me. It seems that the <br/> isn't being interpreted.
How can I achieve this?
It's not a good idea to name the problem "Concatenating strings in EL" if your issue is with neither of those things. You want to create a multi-line title, that's an HTML problem.
Title only accepts text so <br/> will not work but you can put a line break (
) in there:
<h:outputText value="#{cntc.mail }" title="Nom: #{cntc.nom}
Qualite: #{cntc.qualite}" />
Note that this may not work in every browser.

setting textarea text based on current input field

I have two input fields
input(ng-model='form.firstName', name='firstName', id='familyName')
and
input(ng-model='form.lastName', name='lastName')
I also have a textarea field
textarea(id='fieldInfo', ng-model='fieldInfo', name='fieldInfo' cols='15', rows='10')
I would like to change the text in the TextArea to "Please enter your first name" when the focus or cursor is in the First Name input and change it to "Please enter your last name" when the is on the last name inout and it should be able to toggle as the user switches focus from first name to last name and last name to first name.
Any assistance will be much appreciated.
Melroy
The ng-focus directive will not work for you if you are using one of the stable 1.0.x versions of AngularJS. However, I have created a working CodePen example of how you could do it without the ng-focus directive.
I created my own on-focus directive that evaluates an expression, which results in an update to the scope model being used by the textarea. I'm sure it could use some refinement, but the concept should still work for your application.
You can use the ngFocus directive if you are using angular 1.2.0.
In your controller:
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', ['$scope', function($scope) {
$scope.text = "";
}]);
And in your view:
<input type="text" data-ng-model="form.name" ng-focus="text = 'Please enter your first name'" />
<input type="text" data-ng-model="form.last" ng-focus="text = 'Please enter your last name'" />
<textarea name="area" id="textarea" cols="30" rows="10"> {{ text }} </textarea>
You can check this fiddle
Edit: Wrong fiddle link

Sharepoint Custom Field Render Pattern: Render to multiple fields

Initial Question
Can I render the data from one field into multiple columns?
Background
I have created a custom field that contains a drop down list and two text boxes. The idea is that users can select a supplier from the drop down list that is connected to a list of suppliers. Which will get the contact name and number of the supplier and populate the corresponding textboxes.
I have done it this way as it is important to be able to override the contact number and the address but the client wants to see the defaults.
Heres what it looks like:
On saving the new entry the value of the field is saved as follows:
;#1;#Supplier 1;#Contact Name;#01234 567890;#
I chose to save the data in this was so I can treat it like a multi-column field when I render it.
I am using the below code to split the data and override the display pattern for the list view:
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr>
<Column />
</Expr>
<Case Value="" />
<Default>
<!--<Column SubColumnNumber="0" HTMLEncode="TRUE" />
<HTML><![CDATA[<br/>]]></HTML>-->
<Column SubColumnNumber="1" HTMLEncode="TRUE" />
<HTML><![CDATA[ - ]]></HTML>
<Column SubColumnNumber="2" HTMLEncode="TRUE" />
<HTML><![CDATA[ - ]]></HTML>
<Column SubColumnNumber="3" HTMLEncode="TRUE" />
<HTML><![CDATA[]]>]></HTML>
</Default>
</Switch>
</RenderPattern>
This allows me to present the data to the end user as follows:
Question
I would like to be able to display this split data in seperate columns. I notice that the build in title field SharePoint uses has four types of columns you can add to a view for a single field. I am trying to reproduce this kind of functionality so each section of the data can be added or removed from views. Is this possible?
It turns out you have access the list item which meant I was able to simply just add to additional fields within the list item by overriding the UpdateFieldValueInItem method.
Public Overrides Sub UpdateFieldValueInItem()
Me.ItemFieldValue = ddlSupplier.SelectedItem.Value
If Me.Item.Fields.ContainsField(Me.Field.InternalName & "-" & "Telephone") Then
Me.Item(Me.Field.InternalName & "-" & "Telephone") = txtTelephone.Text
End If
End Sub
A much more effective way of doing this.

How to Filter a DropDownList from another DropDownList (SPDataSource + ControlParameter way)

I’m trying to connect two DropDownList (ddlCountry and ddlCity) together. I want that when the user changes the Country, the ddlCity is updated consequently.
To do it, I created two lists:
· Country (ID, Title)
· City (ID, Title, Country) [Country is a lookup field]
Then I created an ASPX page with 2 DropDownList connected to Country and City through 2 SPDataSource (dsCountry and dsCity).
When I load my page, the City DropDownList is populated accordingly to the Country DropDownList, but when I change the Country, nothing happens and ddlCity shows null always
This is my code:
<SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="<Query><OrderBy><FieldRef Name='Title' /></OrderBy></Query>" id="dsCountry">
<SelectParameters>
<asp:Parameter Name="ListName" DefaultValue="Country"/>
</SelectParameters>
</SharePoint:SPDataSource>
<p>Country:
<asp:DropDownList runat="server" id="ddlCountry" DataValueField="Title" DataTextField="Title" DataSourceID="dsCountry" AutoPostBack="True" />
</p>
<SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true" selectcommand="<Query><Where><Eq><FieldRef Name="Country" /><Value Type="Lookup">{country}</Value></Eq></Where></Query>" id="dsCity">
<SelectParameters>
<asp:parameter DefaultValue="City" Name="ListName"></asp:parameter>
<asp:controlparameter name="country" controlid="ddlCountry" propertyname="SelectedValue"/>
</SelectParameters>
</SharePoint:SPDataSource>
<p>City:
<asp:DropDownList runat="server" id="ddlCity" DataValueField="Title" DataTextField="Title" DataSourceID="dsCity" />
</p>
Please note:
· In ddlCountry AutoPostBack = True
· In dsCity, in the CAML query there’s a parameter called “country”, connected to ddlCountry through a ControlParameter
I don’t understand why my filtering doesn’t work when I change the country… I can see the page reloading, but nothing happens… any suggestion?
Shouldn't the variable be:
{$country}
Interested in knowing if you ever found a solution.
I realise this is serious thread necromancy, but in case you're still interested, or anyone else finds this through Google...
Try setting the EnableViewState attribute of the second (filtered) dropdown to false. This will force the control to get a new set of data (with the new filter) from the SPDataSource, instead of getting its previous set from before the post back from the View State.
Have a look at this page for this specific example, and this page for a more general overview of the View State and what it does.

Resources