I have a page in Kentico that displays data from a custom table. One of the custom table fields is page title, and I can't figure out how to display the page title field in the...
<title></title>
...tags
The closest thing I can get to it is displaying part of the uri as the title, so /promo/page-title will create a title of
<title>page-title</title>
Wich is less than desirable for three reasons:
/promo/pAgE-TItle will display the title as pAgE-TItle
the dashes are still there from the url
The text from the uri is actually just a slug that represents the data in the custom table (a field named programkey) and is Not always the same as the actual title of the data
(EDIT)
Ok thanks to Raymond, and a bit of fumbling around, this is what I found works (posted in a custom table transformation):
<script runat="server">
private string Title { get; set;}
private string Description { get; set;}
private string Keywords { get; set;}
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
// Get values from custom table
Title = DataBinder.Eval(this.DataItem, "seo_title").ToString();
Description = DataBinder.Eval(this.DataItem, "seo_desc").ToString();
Keywords = DataBinder.Eval(this.DataItem, "seo_keywords").ToString();
// Set values in meta tags
CMSContext.CurrentTitle = Title;
CMSContext.CurrentDescription = Description;
CMSContext.CurrentKeyWords = Keywords;
}
</script>
You can also create a custom macro in which you will use the API to get the custom table data. Then, use this macro in the page title/metadata settings
This should do the trick:
CMSContext.CurrentTitle = "asdasd";
Related
I am selecting multiple lines (ctrl/shift+click) from the grid on the Sales Order screen and want an action to have access to what was selected. How do I access the list of what's selected on the grid from the code behind?
As stated, add the selected screen. First you would add a DAC extension to add the selected field, which is not a DB field.
#region Selected
[PXBool]
[PXUIField(DisplayName = "Selected")]
public virtual bool? Selected { get; set; }
public abstract class selected : PX.Data.BQL.BqlBool.Field<selected> { }
#endregion
From there, you can add the selected field to your table in the UI. Also, ensure that commit changes is set on that field, or an action that you may call to query.
Finally, you can just run a foreach for the view, and check for the selected field you added:
foreach (SOLine line in Base.Transactions.Select())
{
SOLineExt lineExt = line.GetExtension<SOLineExt>();
if (line.Selected == true)
{
//execute code on the record
}
}
In EPiServer 7.5, I've created a NewsArticle model that has several properties for various text fields. A few of these properties have StringLength limitations. For example, the title for a news article is decorated like so:
[Display(
Order = 10,
Name = "Title (Headline)",
Description = "The article's title (headline). Title also appears in the browser tab.",
Prompt = "Article headline or title",
GroupName = SystemTabNames.Content
)]
[Required]
[StringLength(100)]
public override string Title { get; set; }
When adding a new NewsArticle page, I would like to display the input as a longer field than the default width field that the browser displays for elements.
Can I apply a class or style to that will operate on that field when it's rendered in the Add Page interface? Or is there some property that can decorate the property which will make it a longer length?
Here is a screen shot of the interface that I'm referring to. I want to make that Title field wider on that form.
It's quite easy to accomplish with a custom EditorDescritor/UI hint.
Create an editor descriptor (inherit EditorDescriptor), override the ModifyMetadata method, and set:
metadata.EditorConfiguration.Add("style", "width: 300px");
That will add a "style" attribute to the "input" element of the editor, making the textbox wider.
For example, the following will add this to all string properties, without needing to add a UIHint attribute, making textboxes for string properties 300 pixels wide:
[EditorDescriptorRegistration(EditorDescriptorBehavior = EditorDescriptorBehavior.PlaceLast, TargetType = typeof(string))]
public class WideTextboxEditorDescriptor : EditorDescriptor
{
public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
{
base.ModifyMetadata(metadata, attributes);
metadata.EditorConfiguration.Add("style", "width: 300px");
}
}
This is how I go about customizing the look of the CMS editor views in Episerver 7.5 and above.
Create a file EpiCustomizations.css and place it in /ClientResources/Styles/
In your case add this CSS-rule into that file
/* Widen the textbox input in the editor views */
.Sleek .dijitTextBox:not(.epi-categoriesGroup):not(.dojoDndContainer):not(.dijitNumberTextBox ) {
width: 600px !important;
}
Edit/Create a module.config and place it in your root-folder
Insert this into module.config so that the stylesheet is registered
<module>
<clientResources>
<add name="epi-cms.widgets.base" path="Styles/EpiCustomizations.css" resourceType="Style" />
</clientResources>
</module>
Note: You might have to adjust the CSS-selector depending on which version of Episerver you're using.
I have a ternary operator in my MVC4 View:
#(modelrecord.Website == null ? "" : modelrecord.Website.Replace("http://","") )
This works, but I want to make the website record a hyperlink. Is this possible?
Note: I'm replacing the "http://" prefix because it's ugly.
If I put in the actual string with Html.Raw, the angle brackets are escaped, and I still don't get a link.
You should probably be using DataAnnotations and the #Html.DispayFor helper.
public class ModelRecord
{
[DataType(DataType.EmailAddress)]
public String EmailAddress { get; set; }
[DataType(DataType.Url)]
public String Website { get; set; }
}
Then:
email me at #Html.DisplayFor(x => x.EmailAddress)
or visit me online at #Html.DisplayFor(x => x.Website)
The DataTypeAttribute handles things like urls, emails, etc. and formats them depending.
If you want to customize all Urls, you can create a display template for it:
~/Views/Shared/DisplayTemplates/Url.cshtml
#model String
#if (!String.IsNullOrEmpty(Model))
{
#Model.Replace("http://", "")
}
else
{
#:Default text when url is empty.
}
DisplayTemplates (like EditorTemplates) is a convention-based path that MVC uses. because of this, you can place the template in the Shared directory to apply this change site-wide, or you can place the folder within one of the controller folders to only have it apply to that controller (e.g. ~/Views/Home/Displaytemplates/Url.cshtml). Also, Url is one of the pre-defined templates included for use with DisplayType, along with the following:
Url
EmailAddress
HiddenInput
Html
Text
I am using a DevExpress ASPxGridView containing column GridViewDataComboBoxColumn.
The combo box is working correctly in edit mode (allows AJAX style filtering; it inserts, updates and deletes correctly).
The only problem is that in display mode it is displaying the ValueField (numeric id) instead of the TextField.
<dx:GridViewDataComboBoxColumn Width="200px" FieldName="LocationKeyUid" VisibleIndex="0" Caption="Index">
<PropertiesComboBox EnableCallbackMode="true" CallbackPageSize="7" IncrementalFilteringMode="StartsWith"
OnItemsRequestedByFilterCondition="ItemsRequestedByFilterCondition" OnItemRequestedByValue="ItemsRequestedByValue"
TextField="KeyValue" ValueType="System.Int32" TextFormatString="({0}) {1}" ValueField="LocationKeyUid" />
As shown above, I've tried different experiments with setting the TextFormatString, but that seems to be ignored.
I am binding as follows:
IList<LocationKeyGridViewModel> locationKeys = GetLocationKeys();
locationKeyGridView.DataSource = locationKeys;
locationKeyGridView.DataBind();
The class property names (below) are assigned to the TextField and ValueField property settings (above).
public class LocationKeyGridViewModel
{
public int LocationKeyUid { get; set; }
public string KeyValue { get; set; }
}
I have tried changing the FieldName property assignment to the TextField assignment
(i.e. KeyValue) but that generates an Input string is not in correct format error.
Is there something obvious here that I am missing?
I have a Dynamic Data website and while inserting a record into a table, the foreign key relationship shown as a drop-down uses the wrong field for it's select item text value.
How can I change the drop-down such that when working with this one table, it will use a different column as the value in the drop-down?
thank you
The solution is to add a partial class with some attributes from the System.ComponentModel.DataAnnotations namespace & assembly. Notice the [DisplayColumn("Description")] below. That's what field is used to render as the text in a list.
Further reading
[MetadataType(typeof(ProductMetadata))]
**[DisplayColumn("Description")]**
[ScaffoldTable(true)]
public partial class Product
{
}
public class ProductMetadata
{
[UIHint("TextReadOnly")]
public string CreatedBy;
[UIHint("TextReadOnly")]
public string CreatedDate;
[ScaffoldColumn(false)]
public EntityCollection<OrderItem> OrderItem;
}