Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Umbraco Truncate

Umbraco Truncate doesn't seem the work for me, it constantly errors while I'm using the right code (according to the internet). I can't figure out what's wrong with it.

Error code:

Compiler Error Message: CS1502: The best overloaded method match for 'Umbraco.Web.UmbracoHelper.Truncate(System.Web.IHtmlString, int)' has some invalid arguments

Code:

<div class="grid-item col-xs-12 col-sm-6 col-md-4">
                <figure>
                    <a href="@item.Url">
                        @if (@item.GetPropertyValue("image") != null)
                        {
                            <img src="@Umbraco.Media(item.GetPropertyValue("image").ToString()).Url?anchor=center&mode=crop&w=400&h=275"/>
                        <figcaption>
                            <h5>@item.GetPropertyValue("title")</h5>
                            <p>@Umbraco.Truncate(item.GetPropertyValue("intro"),200)</p>
                        </figcaption>
                        }
                        else
                        {
                            <figcaption>
                                <h5>@item.GetPropertyValue("title")</h5>
                                <p>@item.GetPropertyValue("intro")</p>
                            </figcaption>
                        }
                    </a>
                </figure>
            </div>

Not sure why <p>@Umbraco.Truncate(item.GetPropertyValue("intro"),200)</p> does not work

like image 376
Mik3NL Avatar asked Mar 19 '26 01:03

Mik3NL


1 Answers

It should be

@Umbraco.Truncate(item.GetPropertyValue<string>("intro"), 200);

instead of

@Umbraco.Truncate(item.GetPropertyValue("intro"), 200);

because item.GetPropertyValue("intro") is of type object and you need string as the first parameter.

like image 119
Davor Zlotrg Avatar answered Mar 20 '26 18:03

Davor Zlotrg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!