I have a requirement to add a class to a p-tag if it has an a-tag child, like this:
<p class="read-more-link">
Link
</p>
I've tried the following without success (this is C# in EPiServer):
new {title="Read more link", selector="p", classes="read-more-link" } // this allows user to add class to any p
new {title="Read more link", selector="p > a", classes="read-more-link" } // this adds class to a tag
new {title="Read more link", selector="p > a", classes="read-more-link", wrapper="true" } // this does nothing
new {title="Read more link", selector="p > a", block="p", classes="read-more-link", wrapper="true" } // this does nothing
new {title="Read more link", selector="a", block="p", classes="read-more-link", wrapper="true" } // this does nothing
Anyone know how to solve this?
You should be using a wrapper, see https://www.tiny.cloud/docs/configure/content-formatting/#wrapper
Related
I'm building a search application and am trying to get some results links that appear in tab format to work. Much like you see on google.com/search=?user_query and bing.com/search=?user_query... where after you submit the initial query, you can click on "Images", "Shopping" and "News" for example and a different results view is rendered based on the the result link/tab that you clicked.
I'm using ReactiveSearch to build my search UI. So far I have this:
ResultNavigationTabs.tsx to build the link tabs
class ResultNavigationTabs extends Component {
render() {
const { classes, items, location: { pathname } } = this.props;
return (
<ul className={classes.nav}>
{items.map(item => (
<Link to={item.link} key={item.text}>
<li className={item.link.startsWith(pathname) ? "active" : ""}>
{item.text}
</li>
</Link>
))}
</ul>
);
}
}
export default withStyles(styles)(withRouter(ResultNavigationTabs));
I then render this component in my ResultsViewPage.tsx like so:
render() {
const { selected } = this.state;
...(omitted for brevity)
<ResultNavigationTabs2
className={classes.myNavigationTabs}
items={[
{ text: "Web", link: `/search?q="${selected}"` },
{ text: "News", link: `/news?q="${selected}"` },
{ text: "Shopping", link: `/shopping?q="${selected}"` },
]}
/>
The links do render but they do not work. If I hover over the links, the search query string is empty (http://localhost:3000/search?q=%22%22). If you've worked with ReactiveSearch, it should be: http://localhost:3000/search?q=%22user%20query%22.
I have had it working but only when I render ResultNavigationTabs in the same file as the search box (DataSearch in ReactiveSearch language). However, if I do that it appears right below the search box in the Header instead of the results area.
I need to figure out a way to render ResultNavigationTabs in the ResultsViewPage.tsx file with working links.
After doing some more thoughtful searching, I found the answer right here on SO! Comes complete with 2 CodeSandBox demos as well - check them out.
I created an action sheet containing some options
when I select an option I want it to be highlighted.
I took the code from here
https://ionicframework.com/docs/components/#action-sheets
can someone help me please
You can use some (S)CSS to style it with a pseudo-class like :active or :hover. To include your own CSS classes to the action sheet you could use its cssClass property when creating it. Like so:
let actionSheet = this.actionSheetCtrl.create({
title: 'Ionic Action Sheet',
cssClass: 'your-custom-class',
buttons: [
{
text: 'Button 1',
cssClass: 'custom-button-1-class',
handler: () => {
console.log("Button 1 picked!");
}
}
]
});
By doing that, you can use custom CSS classes to style each button (option) of your action sheet, as well as the action sheet itself. If you wanted to, say, make Button 1 have a black background whenever a user "activated" it, you could write:
.custom-button-1-class:active {
background-color: black;
}
So right now I have a partial view that just has a list of possible actions, here is the main portion:
<%= Html.ActionLink("Show", "Show", new { id = dbId, css="/Content/Site.css" }) %> |
<%= Html.ActionLink("Edit", "Edit", new { id = dbId }) %> |
<%= Html.ActionLink("Delete", "Delete", new { id = dbId }, new { #class = "deleteLink" })%>|
<%= Html.ActionLink("Print", "Show", new { id = dbId, css="/Content/Other.css"}) %>
Essentially, there is a Show and and Print option, I decided it would be more convenient to not create a new view for print, and just overload the Show Action by passing an extra parameter that would tell which CSS to display, and then use ViewData to set the CSS for the view.
Is this good practice?
Should I create a new view? They are completely the same except for the CSS.
If the css is the only thing that is different, you could just include the css and set the media type to be picked up when the user prints from the browser, e.g.:
<style media="print" ...
I've got a dropdownlist:
<%= Html.DropDownList("ddlNames", new SelectList(Model.NameList, "ID", "Name"))%>
I've got an ActionLink:
<%: Html.ActionLink("edit", "Edit", "Members", new { area = "MembersArea", id = XXX }, null)%>
I want the value of the dropdownlist in the XXX.
So I want to use values from controls on a view in the ActionLink.
Is that possible in a simple manner?
thanks,
Filip
You can't do this because the html helpers execute at the server side while the dropdown value can change at the client side. The only way to achieve it is to use javascript. You could register for the onchange event of the dropdown and modify the value of the href of the anchor:
$(function() {
$('#ddlNames').change(function() {
var value = this.value; // get the selected value
// TODO: modify the value of the anchor
});
});
This is probably not the best solution because the routes are configured on the server side and in order to modify the value of the link you need to do some string manipulation on the client side.
As an alternative you could use a form and a submit button instead of an anchor. This way the selected value of the dropdown will be automatically sent to the server and you don't need any javascript:
<% using (Html.BeginForm("Edit", "Members", new { area = "MembersArea" })) { %>
<%= Html.DropDownListFor(x => x.SelectedName,
new SelectList(Model.NameList, "ID", "Name"))%>
<input type="submit" value="Edit" />
<% } %>
Instead of modifying the value of the anchor every time a relevant dropdown is changed, just modify it once, on click.
Example using Razor:
#Html.DropDownList("DropDownFirstNames", new SelectList(Model.FirstNames, "ID", "Name"))
#Html.DropDownList("DropDownLastNames", new SelectList(Model.LastNames, "ID", "Name"))
#Html.ActionLink("Submit name", "ActionName", "ControllerName", null, new { #id = "SubmitName" })
<script type="text/javascript">
$('#SubmitName').click(function () {
var first = $('#DropDownFirstNames').val();
var last = $('#DropDownLastNames').val();
var path = '#Url.Content("~/ControllerName/ActionName")' + "?firstId=" + first + "+&lastId=" + last
$(this).attr("href", path);
});
</script>
I have two different areas, and I have a route in one of those areas that is specific to that area, but I need to generate a link to that route using Html.RouteLink from another area (it's how you get over into the new area) but it won't work... It doesn't seem possible to use RouteLink to routes in a different area.
What is the best way around this? Should I just define a new route in the other area and name it differently?
UPDATE (code):
In master page in the main area (I've tried it multiple ways, all of which have produced same result):
<a href="<%= Url.Action("Index", "Home", new { area = "CustomerSite", route = "CustomerSite_preview", domain = (string)ViewData["DomainName"] }, null) %>">
In the CustomerSite area registration as the first route registered:
context.MapRouteLowercase(
"CustomerSite_preview",
"preview/{domain}/{controller}/{action}/{id}",
new { area = "CustomerSite", controller = "Home", action = "Index", id = "" },
new { isCustomerSite = new CustomerSiteRouteConstraint() },
new string[] { "GrayHills.CarLotHosting.Web.Areas.CustomerSite.Controllers" }
);
In your route object you just need a property named area with the name of the area.
Html.RouteLink("My Link Text",
new { area = "MyArea", controller = "MyController" ... },
null);
You need to change your route definition - see the answer ASP.NET MVC Url.Action routing error for more info.
In essence, your route should look as follows since you explicitly supply the controller name and action:
context.MapRouteLowercase(
"CustomerSite_preview",
"preview/{domain}/home/index/",
new { area = "CustomerSite"
, controller = "Home"
, action = "Index"},
new { isCustomerSite = new CustomerSiteRouteConstraint() },
new string[] {
"GrayHills.CarLotHosting.Web.Areas.CustomerSite.Controllers"}
The Url.Action will look like
<a href="<%= Url.Action("Index"
, new {domain = (string)ViewData["DomainName"] }
, null) %>">
which will result in a Url like http://localhost:56291/preview/somedomainname/home/index