1
00:00:00,270 --> 00:00:07,920
In this video, we are going to create a utility function to be able to truncate post description.

2
00:00:08,160 --> 00:00:15,540
So inside the utils, I'm going to create one file and I'll call it as helpers.

3
00:00:19,280 --> 00:00:26,450
This file is going to contain our custom function to be used, and the first function I'm going to create

4
00:00:26,450 --> 00:00:28,070
is called truncate.

5
00:00:30,450 --> 00:00:32,340
Is equal to cost.

6
00:00:32,369 --> 00:00:39,270
Try and kit post and I'll pass in the post that I want to truncate.

7
00:00:43,870 --> 00:00:47,500
And I'm going to check the length of the post.

8
00:00:47,500 --> 00:00:59,320
So if the post does length is more than 100, then I'm going to retain the post.

9
00:00:59,660 --> 00:01:01,450
Dot substring.

10
00:01:06,310 --> 00:01:12,550
And this method takes into argument that is a starting point and where we want to end.

11
00:01:12,700 --> 00:01:21,010
I want to start at zero and end at 100, and then I want to contact with this ellipsis.

12
00:01:21,010 --> 00:01:25,810
Ask that could dot, dot, dot, dot.

13
00:01:26,110 --> 00:01:26,710
Else.

14
00:01:26,710 --> 00:01:29,260
I'm going to return the original post.

15
00:01:29,560 --> 00:01:32,950
Lastly, I need to export this one.

16
00:01:37,410 --> 00:01:38,070
TRUNCATE.

17
00:01:38,370 --> 00:01:40,260
So how are you going to use it?

18
00:01:40,290 --> 00:01:44,280
We are going to use this method inside the template.

19
00:01:44,280 --> 00:01:46,440
So how are you going to use it?

20
00:01:46,710 --> 00:01:53,100
You may be thinking that we can require this file inside the templates, but it will not work.

21
00:01:53,130 --> 00:01:59,760
We are going to take an advantage of the app look as we did for this one.

22
00:01:59,760 --> 00:02:05,130
So anything we add to the low cost, we're going to have it inside the template.

23
00:02:05,130 --> 00:02:09,990
So above here I'm going to add what is called helpers.

24
00:02:11,650 --> 00:02:16,570
And I'm going to make use of app dot low cost.

25
00:02:16,570 --> 00:02:21,070
And then I want to add this method called truncate post.

26
00:02:21,370 --> 00:02:26,260
I need to require the function as truncate post, which is this one.

27
00:02:27,520 --> 00:02:32,970
So I'm assigning a variable to the function call as truncate post.

28
00:02:32,980 --> 00:02:36,940
So inside my template I have access to this.

29
00:02:36,940 --> 00:02:40,810
So where I want to use it, I can go ahead and then use that.

30
00:02:40,810 --> 00:02:48,790
So let's locate the home page, which is a views folder, and here we go for this.

31
00:02:48,790 --> 00:02:53,080
Let's look at the description, which is this.

32
00:02:53,380 --> 00:03:00,130
So I'm going to remove this one and make this of truncate post.

33
00:03:00,430 --> 00:03:05,140
It must be the same and outpace the description.

34
00:03:05,380 --> 00:03:09,460
So now when I refresh it, let's have a look.

35
00:03:10,030 --> 00:03:15,730
I have this error meaning that it couldn't find the variable called truncate post.

36
00:03:15,730 --> 00:03:20,470
So let me save it and let me copy the name.

37
00:03:20,470 --> 00:03:23,440
And in here, let me replace with that.

38
00:03:23,440 --> 00:03:25,990
I think I made some typing mistake.

39
00:03:25,990 --> 00:03:32,830
So let's refresh it and you can see that it has truncated the description.

40
00:03:33,190 --> 00:03:38,260
And where I want to use the truncate is inside the profile.

41
00:03:38,260 --> 00:03:41,080
And I also want to truncate this one.

42
00:03:41,080 --> 00:03:44,290
So I'm going to copy this one.

43
00:03:44,290 --> 00:03:46,690
And let's go to the profile.

44
00:03:53,430 --> 00:03:56,070
And let's locate the description.

45
00:03:56,070 --> 00:03:58,350
So I'm going to paste this one.

46
00:03:59,310 --> 00:04:02,280
All right, so let's refresh it.

47
00:04:03,710 --> 00:04:06,350
And we have it as that.

48
00:04:06,470 --> 00:04:13,580
And for the image, we can use cases by providing what is called minimum height of the image.

